Intraday Candle Data Deprecatedโ
API to retrieve OHLC (Open, High, Low, Close) values for instruments during the current trading day. Data is accessible for 1-minute and 30-minute intervals from the beginning of the market session. For real-time candlestick updates, it is advisable to utilize the Market Update Stream.
Requestโ
curl --location 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute' \
--header 'Content-Type: application/json' \
--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.
Path Parametersโ
| Name | Required | Type | Description |
|---|---|---|---|
| instrument_key | true | string | The unique identifier for the financial instrument for which historical data is being queried. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| interval | true | string | Specifies the time frame of the candles. Possible values: 1minute, 30minute. |
Responses
- 200
- 4XX
Response Bodyโ
{
"status": "success",
"data": {
"candles": [
[
"2023-10-19T15:15:00+05:30",
2305.3,
2307.05,
2301,
2304.65,
559982,
0
],
[
"2023-10-19T14:45:00+05:30",
2309.1,
2310.75,
2305.25,
2305.3,
740124,
0
]
]
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Contains OHLC values for all instruments across various timeframes. |
| data.candles | array[] | Array of candle data, each presented as an array with sequential elements representing trading activity. |
| data.candle[0] | number | Timestamp: Indicating the start time of the candle's timeframe. |
| data.candle[1] | number | Open: The opening price of the asset for the given timeframe. |
| data.candle[2] | number | High: The highest price at which the asset traded during the timeframe. |
| data.candle[3] | number | Low: The lowest price at which the asset traded during the timeframe. |
| data.candle[4] | number | Close: The closing price of the asset for the given timeframe. |
| data.candle[5] | number | Volume: The total amount of the asset that was traded during the timeframe. |
| data.candle[6] | number | Open Interest: The total number of outstanding derivative contracts, such as options or futures. |
Error codesโ
| Error code | Description |
|---|---|
| UDAPI1021 | Instrument key is of invalid format - The provided instrument key doesn't conform to the expected format. |
| UDAPI1020 | Interval accepts one of (1minute,30minute,day,week,month) - Ensure the 'interval' is one of the specified values. |
| UDAPI100011 | Invalid Instrument key - The instrument key you provided doesn't match any of the recognized keys in the system. |
Sample Codeโ
Get intraday candle data with a 1-minute intervalโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Check the response status
if response.status_code == 200:
# Do something with the response data (e.g., print it)
print(response.json())
else:
# Print an error message if the request was not successful
print(f"Error: {response.status_code} - {response.text}")
const axios = require('axios');
const url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
// Do something with the response data (e.g., print it)
console.log(response.data);
})
.catch(error => {
// Print an error message if the request was not successful
console.error(`Error: ${error.response.status} - ${error.response.data}`);
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute";
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.build();
try {
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
// Check the response status
if (httpResponse.statusCode() == 200) {
// Do something with the response body (e.g., print it)
System.out.println(httpResponse.body());
} else {
// Print an error message if the request was not successful
System.err.println("Error: " + httpResponse.statusCode() + " - " + httpResponse.body());
}
} catch (Exception e) {
// Handle exceptions
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/1minute';
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Bearer {your_access_token}\r\n",
'method' => 'GET',
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
// Check for errors
if ($response === FALSE) {
echo 'Error fetching data';
} else {
// Do something with the response (e.g., print it)
echo $response;
}
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_version = '2.0'
api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = '1minute'
try:
api_response = api_instance.get_intra_day_candle_data(instrument_key,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let apiInstance = new UpstoxClient.HistoryApi();
let apiVersion = "2.0";
let instrumentKey = "NSE_EQ|INE669E01016";
let interval = "1minute";
apiInstance.getIntraDayCandleData(instrumentKey, interval, apiVersion, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiException;
import com.upstox.api.GetIntraDayCandleResponse;
import io.swagger.client.api.HistoryApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryApi apiInstance = new HistoryApi();
String apiVersion = "2.0";
String instrumentKey = "NSE_EQ|INE669E01016";
String interval = "1minute";
try {
GetIntraDayCandleResponse result = apiInstance.getIntraDayCandleData(instrumentKey, interval, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryApi#getIntraDayCandleData");
e.printStackTrace();
}
}
}
Get intraday candle data with a 30-minute intervalโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/30minute' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/30minute'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Check the response status
if response.status_code == 200:
# Do something with the response data (e.g., print it)
print(response.json())
else:
# Print an error message if the request was not successful
print(f"Error: {response.status_code} - {response.text}")
const axios = require('axios');
const url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/30minute';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
// Do something with the response data (e.g., print it)
console.log(response.data);
})
.catch(error => {
// Print an error message if the request was not successful
console.error(`Error: ${error.response.status} - ${error.response.data}`);
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/30minute";
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.build();
try {
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
// Check the response status
if (httpResponse.statusCode() == 200) {
// Do something with the response body (e.g., print it)
System.out.println(httpResponse.body());
} else {
// Print an error message if the request was not successful
System.err.println("Error: " + httpResponse.statusCode() + " - " + httpResponse.body());
}
} catch (Exception e) {
// Handle exceptions
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ%7CINE848E01016/30minute';
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Bearer {your_access_token}\r\n",
'method' => 'GET',
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
// Check for errors
if ($response === FALSE) {
echo 'Error fetching data';
} else {
// Do something with the response (e.g., print it)
echo $response;
}
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_version = '2.0'
api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = '30minute'
try:
api_response = api_instance.get_intra_day_candle_data(instrument_key,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let apiInstance = new UpstoxClient.HistoryApi();
let apiVersion = "2.0";
let instrumentKey = "NSE_EQ|INE669E01016";
let interval = "30minute";
apiInstance.getIntraDayCandleData(instrumentKey, interval, apiVersion, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiException;
import com.upstox.api.GetIntraDayCandleResponse;
import io.swagger.client.api.HistoryApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryApi apiInstance = new HistoryApi();
String apiVersion = "2.0";
String instrumentKey = "NSE_EQ|INE669E01016";
String interval = "30minute";
try {
GetIntraDayCandleResponse result = apiInstance.getIntraDayCandleData(instrumentKey, interval, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryApi#getIntraDayCandleData");
e.printStackTrace();
}
}
}
Loading...