Ticker Module

bdineshraj
Can some one please help me to resolve error.
I'm using below code to get data from ontick (KiteTicker)
---------------------------------------------------------------------
api_key = "***********"  # api_key
kws = ""
access_token = input("Access Token: ")
print(access_token)
kws = KiteTicker("api_key", "access_token")

kws.on_ticks = on_ticks
kws.on_close = on_close
kws.on_error = on_error
kws.on_connect = on_connect
kws.on_reconnect = on_reconnect
kws.on_noreconnect = on_noreconnect

kws.connect(threaded=True)
-------------------------------------------------------------------------

I'm getting the below error during connect
2019-10-11 10:23:22,617 ERROR MainProcess ticker.py:660 Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))


I'm using the same apikey and accesstoken in another Kite.Net program and it is working properly. The issue is not with the access token. (I generate the access token using request token in .Net program and then inputting the access token in python program in cmd window.

Please help me to resolve. Thank you.
  • sujith
    It should ideally work. By looking at the above code, it is not possible to figure out the issue. Make sure you don't try to generate access token again in any code once you have a valid access token.
  • bdineshraj
    Hi Sujith,
    I tried running the .Net code with same access token again, it is working fine. But this python ticker module is thowing error.
  • bdineshraj
    bdineshraj edited October 2019
    @sujith - I made mistake. instead of passing string variable i passed string value.
    kws = KiteTicker("api_key", "access_token")

    Now it is throwing different error
    2019-10-11 12:26:39,917 ERROR MainProcess ticker.py:660 Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)

    ----------------------------------------------------
    def on_connect(ws, response):
    global tokens
    print(tokens)
    ws.subscribe(tokens)
    ws.set_mode(ws.MODE_LTP, tokens)
    -------------------------------------------------------------
    Console print value: [256265, 256265]


    Thank you.
  • bdineshraj
    bdineshraj edited October 2019
    Its working now. But after every 3 or 4 ticks the connection closes and reconnects.
    Can someone provide solution for this? Any reference to code sample will help me. Thank you.
  • rakeshr
    @bdineshraj
    The above error occurs when you block on_tick thread with some operation internally.You may check the threading example here.
  • bdineshraj
    @rakeshr Thank you for the help.
This discussion has been closed.