Connection closed: 1006 - connection was closed uncleanly (None)

intermeditatealgo
ticker is getting terminated and reconnected a lot of times, will lose data


code and error:


Tagged:
  • intermeditatealgo
    I am really sorry if I am bothering you guys ,I do not have much experience with handling websocket ,I am used to trading low latency strategies via historical data or market snapshots,any help is highly appreciated
  • sujith
    You can refer to the FAQs here.

    You might be doing some calculation or db dump which is blocking the main thread. One shouldn't block the main thread that is receiving ticks.
  • intermeditatealgo
    @sujith In the above code I am not blocking the main thread,all the calculations are done inside the loop and the connection is threaded as well,I went through the previous discussions regarding the same before posting the error
  • sujith
    Can you paste the code here?
  • intermeditatealgo

    def on_ticks(ws, ticks):
    logging.debug("Ticks: {}".format(ticks))
    # print(ltp,time,token,name,volume)
    def on_connect(ws, response):
    ws.subscribe(token_list)
    ws.set_mode(ws.MODE_FULL,token_list)

    def on_close(ws, code, reason):
    # On connection close stop the main loop
    # Reconnection will not happen after executing `ws.stop()`
    print('yes')
    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_close = on_close
    kws.connect(threaded=True)

    while True:

    def on_ticks(ws, ticks):
    insert_ticks(ticks)


    kws.on_ticks=on_ticks
  • intermeditatealgo
    I am able to get and save ticks only issue is loss of data( not happening at the moment compared for same using historical data)but the websocket drops and connects every 5-10 seconds I will inevitably lose important data in the long run
  • SRIJAN
    SRIJAN edited May 2022
    Are you doing very heavy processing in insert_ticks fucntion ??

    You can try queue method as described here:
    https://kite.trade/forum/discussion/comment/25535/#Comment_25535

    Example:
    https://github.com/zerodha/kite-connect-python-example
  • intermeditatealgo
    @srijan I am just dumping the data from ticks to a database..all the calculations are done on a different programme all together
  • rakeshr
    all the calculations are done on a different programme all together
    You mean different thread in same program?
    If you are facing connection dropout because of blocking in the threaded instance (this is because of python GIL, allowing only a single thread at a times), you will have to use the queue method as highlighted here(solution 1).
  • intermeditatealgo
    Not in the same programme,I don't even read the database in the same programme,I cannot afford delay of x seconds because the requirement of the strategy is close to realtime..I started losing data as of now
  • intermeditatealgo
    can streaming from 2 different web-socket from the same API cause this?
  • SRIJAN
    Yes, it's possible.
    Try the queue method.
  • intermeditatealgo
    @srijan but queue method will delay the dump by x seconds ,I can't lose that
  • intermeditatealgo

    the connection has dropped and reconnected 70 times from 9:15
  • sujith
    You are blocking the main thread that is receiving the ticks hence you are getting disconnected and reconnected.
    We don't have any issue at our end. We use Kite Ticker on all our platforms and used by many Kite Connect users in production also.
  • intermeditatealgo
    @sujith I understand the frustration,but please let me know in the above code pasted above where I am blocking the main thread
  • intermeditatealgo
    Streaming the data using same method from another discount broker ..seems to be working fine ..I am sure that I am not blocking the main thread ..was doing the same thing and that broker has thier issues as well but there is no loss of data.I don't know if the problem is from my end.Please look into it ..you can close the thread
  • rakeshr
    please let me know in the above code pasted above where I am blocking the main thread
    Here inside insert_ticks(ticks)
    while True:

    def on_ticks(ws, ticks):
    insert_ticks(ticks)
  • intermeditatealgo
    But I am doing it as per the second method you prescibed in https://kite.trade/forum/discussion/comment/25535/#Comment_25535
  • rakeshr
    I replied the reason behind the same here in the above post, so you will have to use the queue method.
Sign In or Register to comment.