Need help with fetching options data for Bank Nifty

Hi,

The below code for fetching options data works for ‘NSE_INDEX|Nifty 50’ instrument key and return proper data, but for ‘NSE_INDEX|Nifty Bank’ it does not work. ‘{“status”:“success”,“data”:}’ is the response. Please help.

def get_option_contracts():
url = ‘https://api.upstox.com/v2/option/chain
params = {
‘instrument_key’: ‘NSE_INDEX|Nifty 50’,
‘expiry_date’: ‘2024-05-23’
}
headers = {
‘accept’: ‘application/json’,
“Authorization”: f’Bearer {ACCESS_TOKEN}’
}

response = requests.get(url, params=params, headers=headers)
# Print the response content
pprint(response.text)

Thanks,
Shiva

1 Like

The code you’ve shared is operational and functions correctly. According to NSE India, there are no option contracts available on May 23, 2024 for Bank Nifty. Could you please verify this information independently from your side?

Thank you

Can you please try fetching the data for 2nd May, with ‘instrument_key’: ‘NSE_INDEX|Nifty Bank’.

The National Stock Exchange (NSE) in December had revised the expiry day of Nifty Bank monthly and quarterly contract cycle which is set to be applicable from March 01, 2024.

With this revision, all contracts of Bank Nifty - weekly, monthly and quarterly - will now expire on Wednesdays. Source → Livemint

When we set the expiry to be on Wednesday, the option chain becomes available for Bank Nifty. You can refer to the code snippet below. Rest assured, this code is fully functional

import requests

url = 'https://api.upstox.com/v2/option/chain'
params = {
    'instrument_key': 'NSE_INDEX|Nifty Bank',
    'expiry_date': '2024-05-22'
}
headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer {your_access_token}'
}

response = requests.get(url, params=params, headers=headers)

print(response.json())

1 Like

I was able to get ‘NSE_INDEX|Nifty Bank’ to work by using date as “2024-05-22”, but using this date did not fetch nifty 50 options. For that I had to use date as “2024-05-23”. Don’t know why this is happening.

I modified my code to set the date accordingly for further use.

Bank Nifty option chain works on “2024-05-22” as its a Wednesday, and Nifty 50 works on “2024-05-23” as its a Thursday. As per NSE all contracts of Bank Nifty - weekly, monthly and quarterly - will now expire on Wednesdays. Source → Livemint

Oh I did not know it, Thanks alot.