Option Contractsโ
API to retrieve option contracts for an underlying symbol. It also supports an optional parameter to fetch option contracts for a specific expiry date.
Requestโ
curl --location 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050' \
--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.
Query 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. |
expiry_date | false | string | Expiry date in format: YYYY-MM-DD . |
Responses
- 200
- 4XX
Response Bodyโ
{
"status": "success",
"data": [
{
"name": "NIFTY",
"segment": "NSE_FO",
"exchange": "NSE",
"expiry": "2024-02-15",
"instrument_key": "NSE_FO|37590",
"exchange_token": "37590",
"trading_symbol": "NIFTY 19650 CE 15 FEB 24",
"tick_size": 5,
"lot_size": 50,
"instrument_type": "CE",
"freeze_quantity": 1800,
"underlying_key": "NSE_INDEX|Nifty 50",
"underlying_type": "INDEX",
"underlying_symbol": "NIFTY",
"strike_price": 19650,
"minimum_lot": 50,
"weekly": true
},
{
"name": "NIFTY",
"segment": "NSE_FO",
"exchange": "NSE",
"expiry": "2024-02-15",
"instrument_key": "NSE_FO|37668",
"exchange_token": "37668",
"trading_symbol": "NIFTY 19700 CE 15 FEB 24",
"tick_size": 5,
"lot_size": 50,
"instrument_type": "CE",
"freeze_quantity": 1800,
"underlying_key": "NSE_INDEX|Nifty 50",
"underlying_type": "INDEX",
"underlying_symbol": "NIFTY",
"strike_price": 19700,
"minimum_lot": 50,
"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 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 | The unique identifier used across Upstox APIs for instrument identification. For the regex pattern applicable to this 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 |
Sample Codeโ
Get option contracts of an instrument keyโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Print the response content
print(response.text)
const axios = require('axios');
const url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
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) throws IOException, InterruptedException {
String url = "https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050";
String token = "{your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer " + token)
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Content: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050';
$token = '{your_access_token}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Content: $response\n";
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = "{your_access_token}"
api_instance = upstox_client.OptionsApi(upstox_client.ApiClient(configuration))
try:
api_response = api_instance.get_option_contracts("NSE_INDEX|Nifty 50")
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->options apis: %s\n" % e.body)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let apiInstance = new UpstoxClient.OptionsApi();
apiInstance.getOptionContracts("NSE_INDEX|Nifty 50",null,(error, data, response) => {
if (error) {
console.error(error);
} 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.GetOptionContractResponse;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OptionsApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OptionsApi apiInstance = new OptionsApi();
try {
GetOptionContractResponse result = apiInstance.getOptionContracts("NSE_INDEX|Nifty 50", null);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling API= " + e.getResponseBody());
e.printStackTrace();
}
}
}
Get option contracts of an instrument key with expiry dateโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Print the response content
print(response.text)
const axios = require('axios');
const url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
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) throws IOException, InterruptedException {
String url = "https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28";
String token = "{your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer " + token)
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Content: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28';
$token = '{your_access_token}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Content: $response\n";
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = "{your_access_token}"
api_instance = upstox_client.OptionsApi(upstox_client.ApiClient(configuration))
param = {
'expiry_date': "2024-10-31"
}
try:
api_response = api_instance.get_option_contracts("NSE_INDEX|Nifty 50", **param)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->options apis: %s\n" % e.body)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let opts = {
'expiryDate': "2024-10-31"
}
let apiInstance = new UpstoxClient.OptionsApi();
apiInstance.getOptionContracts("NSE_INDEX|Nifty 50",opts,(error, data, response) => {
if (error) {
console.error(error);
} 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.GetOptionContractResponse;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OptionsApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OptionsApi apiInstance = new OptionsApi();
try {
GetOptionContractResponse result = apiInstance.getOptionContracts("NSE_INDEX|Nifty 50", "2024-10-31");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling API= " + e.getResponseBody());
e.printStackTrace();
}
}
}
Loading...