Put/Call Option Chainโ
API to retrieve put/call option chain for an underlying symbol for a specific expiry date. The Put/Call Option chain is currently not available for the MCX Exchange.
Requestโ
curl --location 'https://api.upstox.com/v2/option/chain?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}'
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 | true | string | Expiry date in format: YYYY-MM-DD. |
Responses
- 200
- 4XX
Response Bodyโ
{
"status": "success",
"data": [
{
"expiry": "2025-02-13",
"pcr": 7515.3,
"strike_price": 21100,
"underlying_key": "NSE_INDEX|Nifty 50",
"underlying_spot_price": 22976.2,
"call_options": {
"instrument_key": "NSE_FO|51059",
"market_data": {
"ltp": 2449.9,
"volume": 0,
"oi": 750,
"close_price": 2449.9,
"bid_price": 1856.65,
"bid_qty": 1125,
"ask_price": 1941.65,
"ask_qty": 1125,
"prev_oi": 1500
},
"option_greeks": {
"vega": 4.1731,
"theta": -472.8941,
"gamma": 0.0001,
"delta": 0.743,
"iv": 262.31,
"pop": 40.56
}
},
"put_options": {
"instrument_key": "NSE_FO|51060",
"market_data": {
"ltp": 0.3,
"volume": 22315725,
"oi": 5636475,
"close_price": 0.35,
"bid_price": 0.3,
"bid_qty": 1979400,
"ask_price": 0.35,
"ask_qty": 2152500,
"prev_oi": 5797500
},
"option_greeks": {
"vega": 0.0568,
"theta": -1.2461,
"gamma": 0,
"delta": -0.0013,
"iv": 50.78,
"pop": 0.15
}
}
}
]
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Data object for put/call option chain. |
| data[].expiry | string | Expiry date (for derivatives). Date format is YYYY-MM-dd. |
| data[].pcr | number | Put Call Ratio. |
| data[].strike_price | number | The strike price for the option. |
| data[].underlying_key | string | The instrument_key for the underlying asset. |
| data[].underlying_spot_price | number | The spot price for the underlying asset. |
| data[].call_options | object | Data object for call options |
| data[].call_options.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[].call_options.market_data | object | Call option market data |
| data[].call_options.option_greeks | object | Call option greeks |
| data[].put_options | object | Data object for call options |
| data[].put_options.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[].put_options.market_data | object | Put option market data |
| data[].put_options.option_greeks | object | Put option greeks |
Option Market Dataโ
| Name | Type | Description |
|---|---|---|
| market_data.ltp | number | Last traded price. |
| market_data.close_price | number | Closed price. |
| market_data.volume | number | The total amount of the asset that was traded during the timeframe. |
| market_data.oi | number | Open interest. |
| market_data.bid_price | number | Bid price. |
| market_data.bid_qty | number | Bid quantity. |
| market_data.ask_price | number | Ask price. |
| market_data.ask_qty | number | Ask quantity. |
| market_data.prev_oi | number | Previous Open interest. |
Option Greek Dataโ
| Name | Type | Description |
|---|---|---|
| option_greeks.vega | number | Rate of change of premium based on change in volatility. |
| option_greeks.theta | number | Measures the impact on premium based on time left for expiry. |
| option_greeks.gamma | number | Rate of change of delta itself. |
| option_greeks.delta | number | Measures the rate of change of options premium based on the directional movement of the underlying. |
| option_greeks.iv | number | Implied Volatality. |
| option_greeks.pop | number | Probability of Profit |
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 put/call option chainโ
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v2/option/chain'
params = {
'instrument_key': 'NSE_INDEX|Nifty 50',
'expiry_date': '2024-03-28'
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, params=params, headers=headers)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/option/chain';
const params = {
instrument_key: 'NSE_INDEX|Nifty 50',
expiry_date: '2024-03-28'
};
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { params, headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
HttpClient httpClient = HttpClient.newBuilder().build();
HttpRequest request = null;
try {
request = HttpRequest.newBuilder()
.uri(new URI("https://api.upstox.com/v2/option/chain?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}")
.build();
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/option/chain';
$params = [
'instrument_key' => 'NSE_INDEX|Nifty 50',
'expiry_date' => '2024-03-28'
];
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
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_put_call_option_chain("NSE_INDEX|Nifty 50", "2024-10-31")
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.getPutCallOptionChain("NSE_INDEX|Nifty 50","2024-10-31",(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.GetOptionChainResponse;
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 {
GetOptionChainResponse result = apiInstance.getPutCallOptionChain("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...