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 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
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)
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
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).
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
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.
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
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.
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
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
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).
Try the queue method.
the connection has dropped and reconnected 70 times from 9:15
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.
insert_ticks(ticks)