Get Expired Option Contracts
API to retrieve expired option contracts for an underlying instrument on a specified expiry date. This API is useful for traders and analysts who want to analyze the historical performance of options and their underlying assets. By providing the instrument key and expiry date, users can obtain detailed information about the expired options, including their trading symbols, strike prices, lot sizes, and other relevant attributes.
Request
curl --location 'https://api.upstox.com/v2/expired-instruments/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27' \
--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.
Query Parameters
| Name | Required | Type | Description |
|---|---|---|---|
| instrument_key | true | string | Key of an underlying instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| expiry_date | true | string | Expiry date for which expired option contracts are required in format: YYYY-MM-DD. |
Responses
- 200
- 4XX
Response Body
{
"status": "success",
"data": [
{
"name": "NIFTY",
"segment": "NSE_FO",
"exchange": "NSE",
"expiry": "2025-04-17",
"instrument_key": "NSE_FO|47983|17-04-2025",
"exchange_token": "47983",
"trading_symbol": "NIFTY 20400 PE 17 APR 25",
"tick_size": 5,
"lot_size": 75,
"instrument_type": "PE",
"freeze_quantity": 1800,
"underlying_key": "NSE_INDEX|Nifty 50",
"underlying_type": "INDEX",
"underlying_symbol": "NIFTY",
"strike_price": 20400,
"minimum_lot": 75,
"weekly": true
},
{
"name": "NIFTY",
"segment": "NSE_FO",
"exchange": "NSE",
"expiry": "2025-04-17",
"instrument_key": "NSE_FO|47982|17-04-2025",
"exchange_token": "47982",
"trading_symbol": "NIFTY 20400 CE 17 APR 25",
"tick_size": 5,
"lot_size": 75,
"instrument_type": "CE",
"freeze_quantity": 1800,
"underlying_key": "NSE_INDEX|Nifty 50",
"underlying_type": "INDEX",
"underlying_symbol": "NIFTY",
"strike_price": 20400,
"minimum_lot": 75,
"weekly": true
}
]
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Data object for expired option contracts. |
| data[].name | string | The name of the option. |
| data[].segment | string | The market segment of the option. Possible values: NSE_EQ, NSE_INDEX, NSE_FO, NCD_FO, BSE_EQ, BSE_INDEX, BSE_FO, BCD_FO, MCX_FO, NSE_COM |
| data[].exchange | string | Exchange to which the instrument is associated. Possible values: NSE, BSE, MCX. |
| data[].expiry | string | Expiry date (for derivatives). Date format is YYYY-MM-dd. |
| data[].instrument_key | string | Also refer to an expired_instrument_key for expired future contract. This is combination of instrument_key and expiry date. For the regex pattern applicable to expired_instrument_key field, see the Field Pattern Appendix. |
| data[].exchange_token | string | The exchange-specific token for the option. |
| data[].trading_symbol | string | The symbol used for trading the option. Format: <underlying_symbol> <strike_price> <CE/PE> <expiry in dd MMM yy> |
| data[].tick_size | number | The minimum price movement of the option. |
| data[].lot_size | number | The size of one lot of the option. |
| data[].instrument_type | string | The type of the option instrument, Possible values: CE, PE |
| data[].freeze_quantity | number | The maximum quantity that can be frozen. |
| data[].underlying_key | string | The instrument_key for the underlying asset. |
| data[].underlying_type | string | The type of the underlying asset, Possible values: COM, INDEX, EQUITY, CUR, IRD. |
| data[].underlying_symbol | string | The symbol of the underlying asset. |
| data[].strike_price | number | The strike price for the option. |
| data[].minimum_lot | number | The minimum lot size for the option. |
| data[].weekly | boolean | Indicates if the option is weekly. |
Error codes
| Error code | Description |
|---|---|
| UDAPI100011 | Invalid Instrument key - You need to provide proper instrument key for this operation. |
| 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 Expired Option Contracts for given instrument with expiry date
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/expired-instruments/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27' \
--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/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27'
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/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27';
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/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27";
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/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-11-27';
// 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_expired_option_contracts("NSE_INDEX|Nifty 50", "2025-04-30")
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.getExpiredOptionContracts("NSE_INDEX|Nifty 50", "2025-04-24", (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 {
GetOptionContractResponse result = expiredInstrumentApi.getExpiredOptionContracts("NSE_INDEX|Nifty 50", "2025-04-24");
System.out.println(result);
} catch (ApiException e) {
System.out.println("Exception when calling ExpiredInstrumentApi#getExpiredOptionContracts");
System.out.println("Status code: " + e.getCode());
System.out.println("Error message: " + e.getResponseBody());
}
}
}
Loading...