Not able to get streaming data via KiteTicker class

soanrch
soanrch edited August 21 in Python client
I am getting an error -
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
Websocket Error Code: 1006
Reason: connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))

Please let me know what am I doing wrong.
  • soanrch
    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")

    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()


  • salim_chisty
    You may refer to the similar discussion here.
  • soanrch
    Thanks, found my error.
Sign In or Register to comment.