I have a simple question for which I could not find an answer in the forums. Is there a simple way to download the oioptions data for all the strike prices of a given instrument ?I have downloaded data for equity using the zerodha API in python but it is not clear how to download the live options data for all the strike prices (or data the close)
We only offer two types of instruments dump, one is the whole master dump or a instruments dump for an exchange. You can check out the documentation to know more here.
Thank you for your response. So as I understand these are the steps that zerodha wants the users to take: Get the dump of all the instruments in the exchange Search for instrument symbol for all the strikes in the instrument dump Then for each symbol separately, download the prices etc using API like kite.ltp https://kite.trade/docs/pykiteconnect/v3/#kiteconnect.KiteConnect.ltp
Also since the strikes may change every month we have to get the dump every month Is that correct?
Also, I went through the python documentation but could not find any way to extract the total number of contracts (which should be different from volume) for options data. Can you please advise if there is any feature available to extract number of contracts Thanks
Instrument master dump is a copy of the data sent by the exchanges about all the instruments that are traded for the day. It is advised to download and keep the instrument dump in sync every day. We don't have any API for finding the number of options instruments available for a given instrument. It is just one file published by every exchange and we provide the same by merging all segments data in one file. There are no auxiliary APIs to count number of instruments or do any operations on it.
Thank you for your response. I do understand that kiteconnect is not for writing strategies. What I was asking is that is there a way to find out about trading contracts instead of volume. In other words, since options data is different from equities, is there any API or any way that helps the user parse the options data e.g. what is the number of traded contracts for Nifty call option at 12400 ?
Thank you again for your response. I modified the python program that I was using to download ltp prices for equites to download options. I am getting an error after downloading data for 1500 instruments. ERROR: "kiteconnect.exceptions.DataException: Unknown Content-Type (text/html) with response: (b'400 Bad request\nYour browser sent an invalid request.\n\n') "
I am getting this error while running python program and not a browser. I am downloading 100 instruments at a time after sleeping for 2 seconds(tried with upto 50 seconds sleep) per instrument. I looked through documentation to see if I am running into a data limit but looks like I am not. I was downloading strike prices for all Nifty and NiftyIT instruments as an experiment. My use case at present is to download strike prices for Nifty, Bank Nifty and 5 other equities .
Is it possible to do that?
@sujith " "You can use the Quote API to know the volume traded for the day of an instrument." Thank you for your information about quotes. I am using that already in another context. That gives the volume but what we need is number of traded contracts which means I have to write programming code to divide the volume by the lot size. Since lot size for a given instrument can vary regularly and there does not seem to be any API to retrieve the lot size, so it seems that the users are required to figure out the lot size through some other third party mechanisms and then figure out the traded contracts. This makes programs error prone and it would be good if you can suggest an elegant solution But first please help resolve the first issue of getting kiteexception as detailed above Thank you
Can you run it with debug flag true and paste the complete logs here? The volume provided in the Quote gives you the total number of units that are traded. If you need number of lots then you need to divide by lot size. You can get lot size data from the instrument master dump.
Thank you again for your response. I'm not exactly sure how to set the debug flag in the way you are requesting. Can you please elaborate? I did set that the debug flag in the Python log. If I do that, I get thelogging information from the kite python programming code. I am cutting and pasting it here. (in 3 message as when I get an erro message on this website stating that the body of my message is too long. Its a long URL since I am requesting prices for 100 strike prices at a time. Note the 400 None error at the end.
@rvsw It's because of the URL exceeds the max length. You can fetch quote call APIs max for 605 instruments in a single request. Exceeding that, you need to query it in multiple batches.
Is there a simple way to download the options data for all the strike prices of a given instrument?
Maybe you can try out this open python package for the option chain. It uses a combination of symbol and expiry date to fetch option data for all available strike for a given symbol and expiry.
You can check out the documentation to know more here.
Get the dump of all the instruments in the exchange
Search for instrument symbol for all the strikes in the instrument dump
Then for each symbol separately, download the prices etc using API like kite.ltp https://kite.trade/docs/pykiteconnect/v3/#kiteconnect.KiteConnect.ltp
Also since the strikes may change every month we have to get the dump every month
Is that correct?
Thank you
Thanks
We don't have any API for finding the number of options instruments available for a given instrument. It is just one file published by every exchange and we provide the same by merging all segments data in one file.
There are no auxiliary APIs to count number of instruments or do any operations on it.
I modified the python program that I was using to download ltp prices for equites to download options. I am getting an error after downloading data for 1500 instruments.
ERROR:
"kiteconnect.exceptions.DataException: Unknown Content-Type (text/html) with response: (b'400 Bad request\nYour browser sent an invalid request.\n\n')
"
I am getting this error while running python program and not a browser. I am downloading 100 instruments at a time after sleeping for 2 seconds(tried with upto 50 seconds sleep) per instrument.
I looked through documentation to see if I am running into a data limit but looks like I am not.
I was downloading strike prices for all Nifty and NiftyIT instruments as an experiment.
My use case at present is to download strike prices for Nifty, Bank Nifty and 5 other equities .
Is it possible to do that?
@sujith " "You can use the Quote API to know the volume traded for the day of an instrument."
Thank you for your information about quotes. I am using that already in another context. That gives the volume but what we need is number of traded contracts which means I have to write programming code to divide the volume by the lot size. Since lot size for a given instrument can vary regularly and there does not seem to be any API to retrieve the lot size, so it seems that the users are required to figure out the lot size through some other third party mechanisms and then figure out the traded contracts. This makes programs error prone and it would be good if you can suggest an elegant solution
But first please help resolve the first issue of getting kiteexception as detailed above
Thank you
The volume provided in the Quote gives you the total number of units that are traded. If you need number of lots then you need to divide by lot size. You can get lot size data from the instrument master dump.
DEBUG 2020-01-13 _make_request:396 - https://api.kite.trade:443 "GET /quote/ltp?i=NFO%3ANIFTYIT2031216600CE&i=NFO%3ANIFTYIT2031216500CE&i=NFO%3ANIFTYIT2031216400CE&i=NFO%3ANIFTYIT2031216300CE&i=NFO%3ANIFTYIT2031216200CE&i=NFO%3ANIFTYIT2031216100CE&i=NFO%3ANIFTYIT2031216000CE&i=NFO%3ANIFTYIT2031215900CE&i=NFO%3ANIFTYIT2031215800CE&i=NFO%3ANIFTYIT2031215600CE&i=NFO%3ANIFTYIT2031215500CE&i=NFO%3ANIFTYIT2031215400CE&i=NFO%3ANIFTYIT2031215300CE&i=NFO%3ANIFTYIT2030516600CE&i=NFO%3ANIFTYIT2030516500CE&i=NFO%3ANIFTYIT2030516400CE&i=NFO%3ANIFTYIT2030516300CE&i=NFO%3ANIFTYIT2030516200CE&i=NFO%3ANIFTYIT2030516100CE&i=NFO%3ANIFTYIT2030516000CE&i=NFO%3ANIFTYIT2030515900CE&i=NFO%3ANIFTYIT2030515800CE&i=NFO%3ANIFTYIT2030515700CE&i=NFO%3ANIFTYIT2030515600CE&i=NFO%3ANIFTYIT2030515500CE&i=NFO%3ANIFTYIT2031215700CE&i=NFO%3ANIFTYIT2030515400CE&i=NFO%3ANIFTYIT2030515300CE&i=NFO%3ANIFTYIT2030515200CE&i=NFO%3ANIFTYIT2030515100CE&i=NFO%3ANIFTYIT20MAR17600CE&i=NFO%3ANIFTYIT20MAR17400CE&i=NFO%3ANIFTYIT20MAR17300CE&i=NFO%3ANIFTYIT20MAR17200CE&i=NFO%3ANIFTYIT20MAR17100CE&i=NFO%3ANIFTYIT20MAR17000CE&i=NFO%3ANIFTYIT20MAR16900CE&i=NFO%3ANIFTYIT20MAR16800CE&i=NFO%3ANIFTYIT20MAR16700CE&i=NFO%3ANIFTYIT20MAR16600CE&i=NFO%3ANIFTYIT20MAR16500CE&i=NFO%3ANIFTYIT20MAR16400CE&i=NFO%3ANIFTYIT20MAR16300CE&i=NFO%3ANIFTYIT20MAR16200CE&i=NFO%3ANIFTYIT20MAR16100CE&i=NFO%3ANIFTYIT20MAR16000CE&i=NFO%3ANIFTYIT20MAR15900CE&i=NFO%3ANIFTYIT20MAR15800CE&i=NFO%3ANIFTYIT20MAR15700CE&i=NFO%3ANIFTYIT20MAR15600CE&i=NFO%3ANIFTYIT20MAR15500CE&i=NFO%3ANIFTYIT20MAR15400CE&i=NFO%3ANIFTYIT20MAR15300CE&i=NFO%3ANIFTYIT20MAR15200CE&i=NFO%3ANIFTYIT20MAR15100CE&i=NFO%3ANIFTYIT20MAR15000CE&i=NFO%3ANIFTYIT20MAR14900CE&i=NFO%3ANIFTYIT20MAR14800CE&i=NFO%3ANIFTYIT20MAR14700CE&i=NFO%3ANIFTYIT20MAR14600CE&i=NFO%3ANIFTYIT20MAR14500CE&i=NFO%3ANIFTYIT20MAR14400CE&i=NFO%3ANIFTYIT20MAR14300CE&i=NFO%3ANIFTYIT20MAR14200CE&i=NFO%3ANIFTYIT20MAR14100CE&i=NFO%3ANIFTYIT2022016600CE&i=NFO%3ANIFTYIT2022016500CE&i=NFO%3ANIFTYIT2022016400CE&i=NFO%3ANIFTYIT2022016300CE&i=NFO%3ANIFTYIT2022016200CE&i=NFO%3ANIFTYIT2022016100CE&i=NFO%3ANIFTYIT2022016000CE&i=NFO%3ANIFTYIT2022015900CE&i=NFO%3ANIFTYIT2022015800CE&i=NFO%3ANIFTYIT2022015700CE&i=NFO%3ANIFTYIT2022015600CE&i=NFO%3ANIFTYIT2020614500CE&i=NFO%3ANIFTYIT2020614400CE&i=NFO%3ANIFTYIT2020614300CE&i=NFO%3ANIFTYIT20FEB17600CE&i=NFO%3ANIFTYIT20FEB17500CE&i=NFO%3ANIFTYIT20FEB17400CE&i=NFO%3ANIFTYIT20FEB17300CE&i=NFO%3ANIFTYIT20FEB17200CE&i=NFO%3ANIFTYIT20FEB17100CE&i=NFO%3ANIFTYIT20FEB17000CE&i=NFO%3ANIFTYIT20FEB16900CE&i=NFO%3ANIFTYIT20FEB16800CE&i=NFO%3ANIFTYIT20FEB16700CE&i=NFO%3ANIFTYIT20FEB16600CE&i=NFO%3ANIFTYIT20FEB16500CE&i=NFO%3ANIFTYIT20FEB16400CE&i=NFO%3ANIFTYIT20FEB16300CE&i=NFO%3ANIFTYIT20FEB16200CE&i=NFO%3ANIFTYIT20FEB16100CE&i=NFO%3ANIFTYIT20FEB16000CE
It's because of the URL exceeds the max length. You can fetch quote call APIs max for 605 instruments in a single request. Exceeding that, you need to query it in multiple batches.