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 ?
  • salim_chisty
    Kite Connect supports both instrument_token and Exchange: Tradingsymbol representations, but they are not interchangeable across all endpoints. The Exchange: Tradingsymbol format is a convenience alias supported only in quote-type APIs (quote, ltp, ohlc), where it is internally resolved to the instrument token. instrument_token is the primary identifier used for historical data and WebSocket subscriptions.
    There is no separate API to fetch Exchange: Tradingsymbol; it must be derived from the instruments dump file (exchange + tradingsymbol).
    You may refer to the similar discussion here.
Sign In or Register to comment.