Threaded KiteTicker stops updating Ticks on reconnection

I'm running KiteTicker with threaded as in kws.connect(threaded=threaded). After reconnect, it stops updating the ticks and I have to start it again.

Please advice.
  • sujith
    Can you let us know about the setup and the pykiteconnect version?
    Also please include the code and complete stack trace, we will check and get back to you.
  • SharadKothari
    Thanks for your prompt response.

    Here is my code:

    from kiteconnect import KiteTicker, KiteConnect
    import logging

    log = logging.getLogger('Flask.Ticker')

    class KiteWebsocket:
    tick = {}
    kws = None

    def __init__(self):

    def start(self, api_key: str, access_token: str, threaded = True):

    if not KiteWebsocket.kws:'Starting Kite Ticker...')

    KiteWebsocket.kws = KiteTicker(api_key=api_key, access_token=access_token, reconnect=True)
    kws = KiteWebsocket.kws
    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_close = on_close



    def on_ticks(ws, ticks):
    # Callback to receive ticks.
    for t in ticks:
    KiteWebsocket.tick[t['instrument_token']] = t

    def on_connect(ws, response):
    # Callback on successful connect.'Ticker connection successful.')

    def on_disconnect(ws, code, reason):
    log.error('Ticker got disconnected. code = %d, reason = %s', code, reason)

    def on_close(ws, code, reason):
    # On connection close stop the main loop
    # Reconnection will not happen after executing `ws.stop()`

  • rakeshr
    threaded should be True, if you are trying to spawn another thread to handle tick. Also, this should be post ticker callbacks.
    KiteWebsocket.tick[t['instrument_token']] = t
    This operation seems to block the main ticker thread. You can go through this thread to know more about this.
  • SharadKothari
    Thanks for your response.

    Threaded is set as true when the ticker is started by calling start method as under:
    "def start(self, api_key: str, access_token: str, threaded = True):"

    Further, is not thread, it's simply a class variable which stores the last updated tick for the instrument.

Sign In or Register to comment.