How to fetch option data using Zerodha Api in python

gurpreet
We are not able to fetch option data using zerodha api please help us
------------------------------------------------------------------------------------------------------------
This Is my code
option_data = kite.option_chain('NSE') # You can specify the exchange here, like NSE or BSE
# Access option data as per your requirement
print(option_data)
-------------------------------------------------------------------------------
This Is my full login code:
http_session = requests.Session()
url = http_session.get(url='https://kite.trade/connect/login?v=3&api_key='+zerodha_api_key).url
response = http_session.post(url='https://kite.zerodha.com/api/login', data={'user_id':zerodha_user_id, 'password':zerodha_password})
resp_dict = json.loads(response.content)
http_session.post(url='https://kite.zerodha.com/api/twofa', data={'user_id':zerodha_user_id, 'request_id':resp_dict["data"]["request_id"], 'twofa_value':pyotp.TOTP(zerodha_totp_key).now()})
url = url + "&skip_session=true"
response = http_session.get(url=url, allow_redirects=True).url
request_token = parse_qs(urlparse(response).query)['request_token'][0]

kite = KiteConnect(api_key=zerodha_api_key)
data = kite.generate_session(request_token, api_secret=zerodha_api_secrets)
kite.set_access_token(data["access_token"])
symbol= "NIFTY28MAR22500CE"
# Fetch option data
option_data = kite.option_chain('NSE') # You can specify the exchange here, like NSE or BSE
# Access option data as per your requirement
print(option_data)
--------------------------------------------------------------
when i run the code coming error like this:
File "C:\Users\Administrator\PycharmProjects\pythonProject2\main.py", line 43, in login
option_data = kite.option_chain('NSE:NIFTY 50') # You can specify the exchange here, like NSE or BSE
AttributeError: 'KiteConnect' object has no attribute 'option_chain'
  • rakeshr
    option_data = kite.option_chain('NSE')
    This is not related to kiteconnect official clients.
  • gurpreet
    Can we access option data using zerodha api in python or not NSE?
  • gurpreet
    This is not related to kite connect official clients.
    Am not understand what you are say please explain briefly?
  • MAG
    Where did you get the line kite.option_chain('NSE') from? Can you post a link to the source?

    Kiteconnect official api and clients do not have a call for getting option chain.
    Or in other words a ready made option chain is not available for download from zerodha using the kiteconnect api.
  • MAG
    @gurpreet Thats a library written by someone and made public on the internet.
    You will have to contact the person owning that library for support. It has nothing to do with zerodha.

    Also a quick perusal through the code showed at least one severe issue due to which the code may not work especially if the user is trying to retrieve option chain for multiple strike points.
Sign In or Register to comment.