# News

## Overview

The **News** widget allows you to displays latest news on a symbol, exchange, or symbol type.

![News widget](@site/static/img/top-news-widget.png)

## Enable the widget

:::info

The _News_ widget requires quote data.
Therefore, you need to implement the [`getQuotes`](../connecting_data/datafeed-api/trading-platform-methods.md#getquotes), [`subscribeQuotes`](../connecting_data/datafeed-api/trading-platform-methods.md#subscribequotes), and [`unsubscribeQuotes`](../connecting_data/datafeed-api/trading-platform-methods.md#unsubscribequotes) methods within your [Datafeed API](https://charting-library-docs.xstaging.tv/latest/connecting_data/datafeed-api.md).

:::

The [`widgetbar`](../api/interfaces/Charting_Library.TradingTerminalWidgetOptions.md#widgetbar) property of the [Widget Constructor] allows managing the widget panel, including the _News_ widget. To enable the widget, set the [`news`](../api/interfaces/Charting_Library.WidgetBarParams.md#news) property to `true`.

```js
const widget = new TradingView.widget({
    container: "chartContainer",
    locale: "en",
    library_path: "charting_library/",
    datafeed: datafeed,
    symbol: "AAPL",
    interval: "1D",
    //highlight-start
    widgetbar: {
        news: true,
    },
    //highlight-end
})
```

## Connect news

The library does not contain any built-in news providers. Therefore, you should connect a [RSS feed](#rss-feed) or your own [news source](#custom-news-source) using the [`rss_news_feed`] or [`news_provider`] properties, respectively.

:::info

If both `news_provider` and `rss_news_feed` properties are specified, `rss_news_feed` is ignored.

:::

### RSS feed

Use the [`rss_news_feed`] property of the [Widget Constructor] to connect RSS feeds to the library. To do this, specify a [`RssNewsFeedParams`](../api/interfaces/Charting_Library.RssNewsFeedParams.md) object that should contain at least the default RSS configuration.
For each configuration, provide the following properties:

- [`url`](../api/interfaces/Charting_Library.RssNewsFeedInfo.md#url) — a URL that the library should request. The URL can contain tags in curly brackets, such as `{SYMBOL}`, `{TYPE}`, or `{EXCHANGE}`, that the library replaces with values.
- [`name`](../api/interfaces/Charting_Library.RssNewsFeedInfo.md#name) — a feed name that is displayed underneath the news.

```javascript
rss_news_feed: {
    "default": {
        url: "https://articlefeeds.nasdaq.com/nasdaq/symbols?symbol={SYMBOL}",
        name: "NASDAQ"
    }
}
```

You can specify a different RSS for each symbol type or use only one for all symbols. The names of the properties should match the symbol types.

```javascript
rss_news_feed: {
    "default": {
        url: "https://articlefeeds.nasdaq.com/nasdaq/symbols?symbol={SYMBOL}",
        name: "NASDAQ"
    },
    "stock": {
        url: "http://feeds.finance.yahoo.com/rss/2.0/headline?s={SYMBOL}&region=US&lang=en-US",
        name: "Yahoo Finance"
    }
}
```

### Custom news source

You should implement [`GetNewsFunction`](../api/modules/Charting_Library.md#getnewsfunction) and assign it to the [`news_provider`] property to connect any custom news source to the library.
The library calls this function to request data for the widget. In response, you should pass a [`GetNewsResponse`](../api/interfaces/Charting_Library.GetNewsResponse.md) object to the callback function. In this object, specify an array of [`newsItem`](../api/interfaces/Charting_Library.NewsItem.md) objects that contain data for each news item.

```javascript
const widget = new TradingView.widget({
    news_provider: function getNews(symbol, callback) {
        const newsItems = [
            {
                title: "Title 1",
                source: "Source Name",
                published: new Date("2023-12-20 12:34").valueOf(),
                shortDescription: "Hello World, Article 1.",
            },
            {
                title: "Title 2",
                source: "Source Name",
                published: new Date("2023-12-19 12:34").valueOf(),
                shortDescription: "Hello World, Article 2.",
            },
        ];
        callback({
            title: "Latest News Stories",
            newsItems,
        });
    },
});
```

You can specify a URL to the external source in the [`link`](../api/interfaces/Charting_Library.NewsItem.md#link) property of `newsItem`.
This link is opened in a pop-up dialog when a user clicks on the corresponding news item. If `link` is not provided, the information from the [`fullDescription`](../api/interfaces/Charting_Library.NewsItem.md#fulldescription) property is displayed instead.

```javascript
const newsItems = [
    {
        // ..
        link: "https://www.example.com/test",
    },
]
```

To request news from scratch, for example, when an event occurs, call the [`refresh`](../api/interfaces/Charting_Library.INewsApi.md#refresh) method from `INewsApi`, which can be retrieved with the [`news`](../configuration/widget-methods.md#news) method.

```javascript
const widget = new TradingView.widget({
    // Widget options
});

async function someEventHandler() {
    const newsApi = await widget.news();
    newsApi.refresh();
}
```

[Widget Constructor]: https://charting-library-docs.xstaging.tv/latest/configuration/Widget-Constructor.md
[`rss_news_feed`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.TradingTerminalWidgetOptions#rss_news_feed
[`news_provider`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.TradingTerminalWidgetOptions#news_provider

---

## Sitemap

- [All documentation pages](https://charting-library-docs.xstaging.tv/llms.txt)
- [Full page map with headings](https://charting-library-docs.xstaging.tv/docs_map.md)
