kws.connect() Does not yield any results

puru129
I am new to the kite.dev forum and coding in general.. I tried following the exact steps and resolved bugs in the way, thanks to this forum only.. But after everything is done, I am not getting any data after executing kws.connect(), I am also not getting any error. I am trying during the market hours only.

Pls help
  • rakeshr
    Are you sure about using the correct instrument_token to subscribe for the websocket feed?
    Here is a WebSocket usage example for the Python client.
  • puru129
    @rakeshr I am using the exact same code mentioned in the link. The instrument token would be of reliance if I understood correctly
  • puru129
    @rakeshr I am using the instrument_token 738561

    Am I doing something wrong?
  • rakeshr
    The instrument token is correct. Can you paste here your websocket code? I will take a look.
  • puru129
    puru129 edited May 2023
    Thanks for your response, @rakeshr. My code is as below



    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker
    import logging

    api_key = ''
    api_secret = ''
    kite = KiteConnect(api_key)
    kite.login_url()
    request_token = ''
    kite.generate_session(request_token, api_secret)
    access_token = ''
    public_token = ''

    # Websocket code below

    kws = KiteTicker(api_key, access_token)

    def on_ticks(ws, ticks):
    logging.debug("Ticks: {}".format(ticks))

    def on_connect(ws, response):
    ws.subscribe([1304833]) # Zomato
    ws.set_mode(ws.MODE_FULL, [1304833])

    def on_close(ws, code, reason):
    ws.stop()

    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_close = on_close

    kws.connect()



  • puru129
    Hi @rakeshr sorry to bother you again, but this is a blocker in my learning process. Pls help
  • puru129
    puru129 edited May 2023
    Hi @rakeshr

    Solved the problem. Made 3 changes, not sure what exactly worked:

    - uninstalled and re-installed websocket library
    - Added this to the code:
    logging.basicConfig(level=logging.DEBUG)
    - Added this also to the code:
    kite.set_access_token('my_access_token')
  • rakeshr
    logging.basicConfig(level=logging.DEBUG)
    You will need to enable/set debug level logging as you are logging ticks here logging.debug("Ticks: {}".format(ticks)). You won't need to, if you direct print the ticks, print(ticks).
    kite.set_access_token('my_access_token')
    I have edited out your publically posted access_token. Avoid posting any account-related credentials, as it can lead to compromise. Access token need to be set to make API or WebSocket connection. This documentation explains login flow in detail.
  • puru129
    Thanks @rakeshr I took care of it in the earlier post, but somehow made the mistake in my later post.
This discussion has been closed.