Get Expired Historical Candle Data
This API extends the functionality of the existing Get Historical Candle Data API by allowing users to query data for expired contracts.
This API is particularly useful for traders and analysts who need to analyze past performance and trends of expired contracts.
It provides historical Open, High, Low, Close (OHLC) data for expired contracts, available across multiple time intervals including: 1minute
, 3minute
, 5minute
, 15minute
, 30minute
and day
.
Request
curl -X 'GET' 'https://api.upstox.com/v2/expired-instruments/historical-candle/NSE_FO%7CNIFTY22D0117800CE/day/2022-11-30/2022-11-01'
--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 |
---|---|---|---|
expired_instrument_key | true | string | The unique identifier for the expired financial instrument for which historical data is being queried. This key is combination of normal instrument key and expiry date. The expired_instrument_key key must match the regex pattern specified in the Field Pattern Appendix. |
interval | true | string | Specifies the time frame of the candles. Possible values: 1minute , 3minute ,5minute ,15minute ,30minute , day . |
to_date | true | string | The ending date (inclusive) for the historical data range. Format: YYYY-MM-DD . |
from_date | true | string | The starting date for the historical data range. Format: YYYY-MM-DD . |
Responses
- 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 expired contracts 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. |
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 expired keys in the system. |
UDAPI1088 | Invalid date - You need to provide the expiry_date in proper format: YYYY-MM-DD |
UDAPI1149 | This API is available exclusively with an Upstox Plus plan subscription - Please upgrade to the Plus plan to gain access. |
Sample Code
Get Historical Candle Data for Expired Instruments
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/expired-instruments/historical-candle/NSE_FO|73507|24-04-2025/30minute/2025-04-24/2020-02-24' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/expired-instruments/historical-candle/NSE_FO|73507|24-04-2025/30minute/2025-04-24/2020-02-24'
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/expired-instruments/historical-candle/NSE_FO|73507|24-04-2025/30minute/2025-04-24/2020-02-24';
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/expired-instruments/historical-candle/NSE_FO|73507|24-04-2025/30minute/2025-04-24/2020-02-24";
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/expired-instruments/historical-candle/NSE_FO|73507|24-04-2025/30minute/2025-04-24/2020-02-24';
// Initialize cURL session
$curl = curl_init();
// Set cURL options
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}'
]
]);
// Execute the request
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Check for errors
if (curl_errno($curl)) {
echo 'Error: ' . curl_error($curl);
} else if ($httpCode != 200) {
echo 'Error: HTTP status code ' . $httpCode;
} else {
// Process the successful response
echo $response;
}
// Close cURL session
curl_close($curl);
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.ExpiredInstrumentApi(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_expired_historical_candle_data("NSE_FO|54452|24-04-2025", "1minute", "2025-04-24", "2025-04-24")
print(response)
except ApiException as e:
print("Exception when calling expired instrument api: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let expiredInstrumentsApiInstance = new UpstoxClient.ExpiredInstrumentApi();
expiredInstrumentsApiInstance.getExpiredHistoricalCandleData("NSE_FO|54452|24-04-2025", "1minute", "2025-04-24", "2025-01-03", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
import com.upstox.auth.*;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
ExpiredInstrumentApi expiredInstrumentApi = new ExpiredInstrumentApi();
try {
GetHistoricalCandleResponse result = expiredInstrumentApi.getExpiredHistoricalCandleData("NSE_FO|54452|24-04-2025", "30minute", "2025-06-04", "2002-06-04");
System.out.println(result);
} catch (ApiException e) {
System.out.println("Exception when calling ExpiredInstrumentApi#getExpiredHistoricalCandleData");
System.out.println("Status code: " + e.getCode());
System.out.println("Error message: " + e.getResponseBody());
}
}
}
Loading...