Historical Candle Data V3
Compared to the standard Historical Candle Data API, API V3 allows users to retrieve data in custom time intervals for each unit (minutes
, hours
, days
, weeks
, and months
), enabling more granular data control and improved flexibility for analysis. The response structure maintains consistency with the standard Historical Candle Data API format, facilitating seamless integration with existing applications and systems.
The API is designed to handle large volumes of data efficiently, ensuring quick response times even for extensive historical queries.
This API is particularly useful for traders and analysts who need to analyze historical price movements and trends in the financial markets.
The API offers OHLC (Open, High, Low, Close) data for instruments across multiple timeframes, with different historical availability and retrieval constraints based on the selected unit and interval as per the below table:
Unit | Interval Options | Historical Availability | Max retrieval record limit |
---|---|---|---|
minutes | 1, 2, ... 300 | Available from January, 2022 | 1 month - Applicable for intervals ranging from 1 to 15 minutes. 1 quarter - Used for intervals greater than 15 minutes, up to the specified to_date. |
hours | 1, 2, ... 5 | Available from January, 2022 | 1 quarter leading up to the to_date. |
days | 1 | Available from January, 2000 | 1 decade leading up to the to_date. |
weeks | 1 | Available from January, 2000 | No limit. |
months | 1 | Available from January, 2000 | No limit. |
Request
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
Additional samples in various languages are available in 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. |
unit | true | string | Specifies the unit for the candles. Possible values: minutes , hours , days , weeks , months . |
interval | true | string | Specifies the interval for the candles. Possible values: 1 , 2 , 3 , ..., 300 for minutes. 1 , 2 , ..., 5 for hours. 1 for days, weeks, and months. |
to_date | true | string | The ending date (inclusive) for the historical data range. Format: 'YYYY-MM-DD'. |
from_date | false | string | The starting date for the historical data range. Format: 'YYYY-MM-DD'. |
- 200
- 4XX
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. |
UDAPI1022 | to_date is required - You must specify the to_date in your request. |
UDAPI100011 | Invalid Instrument key - The instrument key you provided doesn't match any of the recognized keys in the system. |
UDAPI1015 | to_date must be greater than or equal to from_date and Date should be in valid format: yyyy-mm-dd - Ensure that to_date is greater than or equal to from_date and both are in the correct format. |
UDAPI1146 | Invalid unit - The unit you provided is not recognized. Valid options are minutes , hours , days , weeks , or months . |
UDAPI1147 | Invalid interval - The interval you provided is not valid for the specified unit. For example, if the unit is minutes , valid intervals are 1 to 300 . |
UDAPI1148 | Invalid date range - The date range specified in the request is not valid. Ensure that the from_date and to_date are within the acceptable limits for the selected interval. |
Sample Code
Get 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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/1/2025-01-02/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "minutes", "1", "2025-01-02", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", "1", "2025-01-02", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", 1, "2025-01-02", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a 3-minute interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/3/2025-01-02/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/3/2025-01-02/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/3/2025-01-02/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/3/2025-01-02/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/3/2025-01-02/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "minutes", "3", "2025-01-02", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", "3", "2025-01-02", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", 3, "2025-01-02", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a 15-minute interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/15/2025-01-04/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/15/2025-01-04/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/15/2025-01-04/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/15/2025-01-04/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/minutes/15/2025-01-04/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "minutes", "15", "2025-01-04", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", "15", "2025-01-04", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "minutes", 15, "2025-01-04", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a 1-hour interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/1/2025-02-01/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/1/2025-02-01/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/1/2025-02-01/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/1/2025-02-01/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/1/2025-02-01/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "hours", "1", "2025-02-01", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "hours", "1", "2025-02-01", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "hours", 1, "2025-02-01", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a 4-hour interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/4/2025-02-01/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/4/2025-02-01/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/4/2025-02-01/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/4/2025-02-01/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/hours/4/2025-02-01/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "hours", "4", "2025-02-01", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "hours", "4", "2025-02-01", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "hours", 4, "2025-02-01", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a daily interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/days/1/2025-03-01/2025-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/days/1/2025-03-01/2025-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/days/1/2025-03-01/2025-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/days/1/2025-03-01/2025-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/days/1/2025-03-01/2025-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "days", "1", "2025-03-01", "2025-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "days", "1", "2025-03-01", "2025-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "days", 1, "2025-03-01", "2025-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a weekly interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/weeks/1/2025-01-01/2024-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/weeks/1/2025-01-01/2024-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/weeks/1/2025-01-01/2024-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/weeks/1/2025-01-01/2024-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/weeks/1/2025-01-01/2024-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "weeks", "1", "2025-01-01", "2024-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "weeks", "1", "2025-01-01", "2024-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "weeks", 1, "2025-01-01", "2024-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}
Get data with a monthly interval
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/months/1/2025-01-01/2010-01-01' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE848E01016/months/1/2025-01-01/2010-01-01'
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/v3/historical-candle/NSE_EQ%7CINE848E01016/months/1/2025-01-01/2010-01-01';
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/v3/historical-candle/NSE_EQ%7CINE848E01016/months/1/2025-01-01/2010-01-01";
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/v3/historical-candle/NSE_EQ%7CINE848E01016/months/1/2025-01-01/2010-01-01';
$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
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.HistoryV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_historical_candle_data1("NSE_EQ|INE848E01016", "months", "1", "2025-01-01", "2010-01-01")
print(response)
except Exception as e:
print("Exception when calling HistoryV3Api->get_historical_candle_data1: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
const historicalApiInstance = new UpstoxClient.HistoryV3Api();
historicalApiInstance.getHistoricalCandleData1("NSE_EQ|INE848E01016", "months", "1", "2025-01-01", "2010-01-01", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.GetHistoricalCandleResponse;
import com.upstox.auth.*;
import io.swagger.client.api.HistoryV3Api;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
HistoryV3Api historyV3Api = new HistoryV3Api();
try {
GetHistoricalCandleResponse result = historyV3Api.getHistoricalCandleData1("NSE_EQ|INE848E01016", "months", 1, "2025-01-01", "2010-01-01");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HistoryV3Api->getHistoricalCandleData1");
e.printStackTrace();
}
}
}