Stock Options data using python

Hi,
I am able to retrieve Nifty and BankNifty data using python.
Trying the same for stock options but that returns an empty response.

Got the instrument_key from here
and used:

upstox_client.get_put_call_option_chain("NSE_FO|82269", "2024-11-28")

and response is:
{'data': [], 'status': 'success'}

Could someone help?
Thank you.

Hi @sahilshah619
The Get Put Call Option Chain API allows you to retrieve the put/call option chain for an underlying symbol with a specified expiry date, as outlined in the documentation.

If you pass in symbols like “Nifty” or “BankNifty,” you’ll receive their respective option chains. However, “NSE_FO|82269” refers to a specific contract, not an underlying symbol with an option chain, so an empty response is returned. To obtain market details for option contracts, please use the Market Quote API or the Historical Data API.

Thank you.

Hi Ketan,
Got it. Thanks!
I was able to get the entire option chain using the instrument_key under instrument_type = equity.

Quick question: Is there a way to download the instrument file in an automated way (minus using web scraper). is there an api for that?

@Ketan
Also can I pass the time between which I want option data? and not just date?

Certainly, you can automate data extraction from the instruments file. Here’s a Python example using pandas, where I print all the instrument keys. There is no need for web scraper just use the url of the file to load data

import pandas as pd

# Load data
fileurl = 'https://assets.upstox.com/market-quote/instruments/exchange/complete.json.gz'
symboldf = pd.read_json(fileurl)
print(symboldf['instrument_key'])

I hope this helps
Thank you.

1 Like

You cannot pass time as a parameter to the API; however, the response includes the time, so you can filter the data on your end to match your custom time frame.

Thank you.

Alright, great!
Thanks again!

Food for thought, maybe adding a optional argument that lets you add to_time and from_time along with date might be helpful. Just a thought

Thanks for your help!