Get Expiries
API to retrieve all the expiries for a given underlying instrument. This API is useful for traders and analysts who need to know all available expiry dates for a specific instrument to plan their trading strategies accordingly.
Expiries is currently not available for the MCX. The API will retrieve the complete list of expiry dates (including weekly and monthly) for the instrument, covering up to six months of historical expiries.
Request
curl --location 'https://api.upstox.com/v2/expired-instruments/expiries?instrument_key=NSE_INDEX%7CNifty%2050' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Accept: application/json'
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 | Key of an underlying symbol. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
Responses
- 200
- 4XX
Response Body
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | array | List of all available expiry dates in format YYYY-MM-dd |
Error codes
| Error code | Description |
|---|---|
| UDAPI100011 | Invalid Instrument key - You need to provide proper instrument key for this operation. |
| UDAPI1149 | This API is available exclusively with an Upstox Plus plan subscription - Please upgrade to the Plus plan to gain access. |
Sample Code
Get Expiries for given instrument
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/expired-instruments/expiries?instrument_key=NSE_INDEX%7CNifty%2050' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Accept: application/json'
import requests
url = 'https://api.upstox.com/v2/expired-instruments/expiries?instrument_key=NSE_INDEX%7CNifty%2050'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Accept': 'application/json'
}
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/expiries?instrument_key=NSE_INDEX%7CNifty%2050';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Accept': 'application/json'
};
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/expiries?instrument_key=NSE_INDEX%7CNifty%2050";
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.header("Accept", "application/json")
.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/expiries?instrument_key=NSE_INDEX%7CNifty%2050';
// 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',
'Authorization: Bearer {your_access_token}',
'Accept: application/json'
]
]);
// 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_expiries("NSE_INDEX|Nifty 50")
print(response)
except ApiException as e:
print("Exception when calling expired instrument v3 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.getExpiries("NSE_INDEX|Nifty 50", (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 {
GetExpiriesResponse getExpiriesResponse = expiredInstrumentApi.getExpiries("NSE_INDEX|Nifty 50");
System.out.println(getExpiriesResponse);
} catch (ApiException e) {
System.out.println("Exception when calling ExpiredInstrumentApi#getExpiredInstruments");
System.out.println("Status code: " + e.getCode());
System.out.println("Error message: " + e.getResponseBody());
}
}
}
Loading...