Fetching ohlc/ ltp from zerodha API

mpujara

with open("kite_access_token.json","r") as f:
token_data = json.load(f)

access_token = token_data["access_token"]
print(access_token)

kite.set_access_token(access_token=access_token)

instruments = kite.instruments("NSE")

nifty = [i for i in instruments if i["name"] == "NIFTY 50"]
banknifty = [i for i in instruments if i["name"] == "NIFTY BANK"]
print(nifty)
print(banknifty)
nifty_token = nifty[0]["instrument_token"]
banknifty_token = banknifty[0]["instrument_token"]

print(nifty_token)
print(banknifty_token)


print(kite.ohlc(nifty_token,banknifty_token))
print(kite.ohlc("NSE:NIFTY 50"))


This is my code , which is just a small snippet , i just wanted to confirm that how come we use both representations (either passing a token or hardcoding a symbol is working ) , like in the github repo i saw that it is mentioned to use instrument symbol exchange:Trading symbol then how tokens do work ?
also is there a method that gives us the exchange:trading symbol rather than hardcoding one ?
Sign In or Register to comment.