Get Newsโ
API to retrieve news for one or more instruments. You can fetch news articles in three ways โ for specific stocks you're interested in, for instruments you currently hold a position in, or for stocks in your long-term portfolio:
- Specific instruments โ pass
category=instrument_keysalong with the instrument keys you want news for (up to 30 at a time). - Your open positions โ pass
category=positionsand the API automatically fetches news for everything you currently have a position in. - Your holdings โ pass
category=holdingsand the API fetches news for all stocks in your holdings portfolio.
Query Parametersโ
| Name | Required | Type | Description |
|---|---|---|---|
| category | true | string | Category of news to fetch. Allowed values: instrument_keys, positions, holdings. |
| instrument_keys | false | string | Comma-separated list of instrument keys. Required when category is instrument_keys. Maximum 30 keys per request. |
| page_number | false | integer | Page number for pagination. Range: 1โ100. Default: 1. |
| page_size | false | integer | Number of records per page. Range: 1โ100. Default: 100. |
Requestโ
curl --location 'https://api.upstox.com/v2/news?category=instrument_keys&instrument_keys=NSE_EQ%7CINE040H01021' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
For additional samples in various languages, please refer to the Sample code section on this page.
Responses
- 200
- 4XX
Response Bodyโ
{
"status": "success",
"data":{
"NSE_EQ|INE040H01021": [
{
"heading": "SMIDs outperform: Nifty Smallcap 100, Nifty Midcap 100 rise over 2%; Suzlon Energy, Afcons Infra top gainers",
"summary": "On a year-on-year basis, the Nifty Midcap 100 index has gained 13%, while the Nifty Smallcap 100 gauge rose 6%",
"thumbnail": "https://assets.upstox.com/content/assets/images/news/traders-assemble-hero.webp",
"article_link": "https://upstox.com/news/market-news/latest-updates/smids-outperform/article-181757/",
"published_time": 1776251261821
}
]
}
"metadata": {
"page": {
"page_number": 1,
"page_size": 10,
"total_records": 1,
"total_pages": 1
}
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, error |
| data | array | Data object which contains one instrument key mapped to an array of news items for that instrument. |
| data.heading | string | Headline of the news article. |
| data.summary | string | Brief summary of the news article. |
| data.thumbnail | string | URL of the article thumbnail image. |
| data.article_link | string | URL to the full news article. |
| data.published_time | number | Unix timestamp in milliseconds indicating when the article was published. |
| metadata.page.page_number | integer | Current page number returned. |
| metadata.page.page_size | integer | Number of news records returned per page. |
| metadata.page.total_records | integer | Total number of records matching the query. |
| metadata.page.total_pages | integer | Total number of pages available. |
Error codesโ
| Error code | Description |
|---|---|
| UDAPI1189 | Invalid category - The provided category is not valid. Allowed values: instrument_keys, positions, holdings. |
| UDAPI1190 | instrument_keys required - The instrument_keys parameter is required when category is instrument_keys. |
| UDAPI1193 | Instrument key limit exceeded - News can be fetched for a maximum of 30 instrument keys per request. |
Sample Codeโ
Fetch news by instrument keysโ
- Python
- Node.js
- Java
- PHP
import requests
url = 'https://api.upstox.com/v2/news'
params = {
'category': 'instrument_keys',
'instrument_keys': 'NSE_EQ|INE040H01021,NSE_EQ|INE002A01018'
}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, params=params, headers=headers)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/news';
const params = {
category: 'instrument_keys',
instrument_keys: 'NSE_EQ|INE040H01021,NSE_EQ|INE002A01018'
};
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { params, headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class GetNews {
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("https://api.upstox.com/v2/news?category=instrument_keys&instrument_keys=NSE_EQ%7CINE040H01021%2CNSE_EQ%7CINE002A01018"))
.header("Accept", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.GET()
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = 'https://api.upstox.com/v2/news?' . http_build_query([
'category' => 'instrument_keys',
'instrument_keys' => 'NSE_EQ|INE040H01021,NSE_EQ|INE002A01018'
]);
$headers = [
'Accept: application/json',
'Authorization: Bearer {your_access_token}'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
Fetch news for your positionsโ
- Python
- Node.js
- Java
- PHP
import requests
# Use category='holdings' to fetch news for your holdings instead
url = 'https://api.upstox.com/v2/news'
params = {'category': 'positions'}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, params=params, headers=headers)
print(response.json())
const axios = require('axios');
// Use category: 'holdings' to fetch news for your holdings instead
axios.get('https://api.upstox.com/v2/news', {
params: { category: 'positions' },
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
}).then(response => console.log(response.data))
.catch(error => console.error('Error:', error));
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class GetNewsPositions {
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
// Use category=holdings to fetch news for your holdings instead
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("https://api.upstox.com/v2/news?category=positions"))
.header("Accept", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.GET()
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
// Use category=holdings to fetch news for your holdings instead
$url = 'https://api.upstox.com/v2/news?category=positions';
$headers = [
'Accept: application/json',
'Authorization: Bearer {your_access_token}'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
Loading...