Connection error: 1006 followed by ticks for 40mins then no ticks or errors

Around '2019-10-29 12:03:48' , saw the following errors in my logs
Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
The script resumed immediately.. and got valid ticks for about 40mins.. then i dont see any errors too in the logs..

This script has be working fine from past 2 months without any issues...not sure what happened today.
Whats the best way to handle such errors ? Did these error lead to freeze after a while ?
Any best practice to avoid losing the data in such situations ?
I am thinking if i should monitor the on_tick call back..and restart the app if on_tick freezes beyond a threshhold...

My code is very simple. and i use it only to stream the data.. Have only these two call backs.

def on_ticks(ws, ticks):
print("In Ticks: ", tick_no)

def on_connect(ws, response):
print (token_list)
ws.set_mode(ws.MODE_FULL, token_list)

def main():
kws.on_ticks = on_ticks
kws.on_connect = on_connect

  • sujith
    You seem to be blocking the main thread by doing database operations. There is a chance that you might be missing ticks.
    The ideal way is to use multi-threading wherein the main thread only listens to ticks and the other thread will do your operations.

    PS: Never block the main thread while reading Websocket data.
  • Shaj
    Thanks @sujith . I was aware of it and have taken special care to avoid the same. My DB apis are optimized and generally take less than .1secs.. average around .05seconds.
    Even other wise.. in worst case, i would miss the ticks, but they shouldnt freezer for ever. as seen above..unless the db api hangs for some reason.. which is very unlikely...
    I will anyway move it out to a different thread.. didnt do it yet, since the apis were already highly optimized..there was no need...

    Is there anything else i should be doing to recover from such things ? Any other imp call back that i should implement ? for just streaming the data ?
  • sujith
    You always get tick data on the on_ticks callback, errors in on_error callback and text message alerts like order updates from on_message.
Sign In or Register to comment.