Code used - # Get instruments instruments = kite.instruments("NFO") # NFO is the exchange for Futures and Options df_instruments = pd.DataFrame(instruments) log_memory("After loading instruments")
def on_ticks(ws, ticks): # Callback to receive ticks. logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)
def on_close(ws, code, reason): print("Websocket Error Code: ", code) print("Reason: ", reason) # On connection close stop the main loop # Reconnection will not happen after executing `ws.stop()` ws.stop()
# Get instruments
instruments = kite.instruments("NFO") # NFO is the exchange for Futures and Options
df_instruments = pd.DataFrame(instruments)
log_memory("After loading instruments")
kws = KiteTicker(API_SECRET,kite.access_token)
tokens = [14081282]
print(tokens)
def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)
def on_close(ws, code, reason):
print("Websocket Error Code: ", code)
print("Reason: ", reason)
# On connection close stop the main loop
# Reconnection will not happen after executing `ws.stop()`
ws.stop()
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()