I keep getting frequent socket disconnection issue. I would like to know the reason for the same and some solution to fix this. Below are the exception prints.
ERROR:websocket:error from callback >: Gateway connection error ERROR:websocket:error from callback >: socket is already closed. ERROR:websocket:error from callback >: socket is already closed. ERROR:websocket:error from callback >: socket is already closed. ERROR:websocket:error from callback >: socket is already closed. ERROR:websocket:error from callback >: socket is already closed. ERROR:websocket:error from callback >: socket is already closed.
@Srik, It shouldn't be happening, many users are already using this feature even before it was taken live. Can you elaborate what you are doing or make a gist and paste it here?
quoteStreamCfg: List = my list of 170 scrips ws.subscribe(List) ws.set_mode(ws.MODE_FULL,List)
Generally on some days I don't face any problem, but some days I keep getting the mentioned error. One more thing I observed is that if I increase the number of scrips in my list to close to 200 I face this issue more frequently.
I have subscribed to 170 scrips. I think the on_tick will not be called with all the 170 scrips data but only with those scrips that are changed from the last tick. Correct me if my understanding is wrong. So in any tick I will be handling some scrips data.
Please let me know if there is any latency requirement or limitation that the user software should abide to.
Hi @Srik, Yes, you get data only when there is a change in data. Even if you are subscribed to 20 to 30 scrips, single thread for processing all ticks is not a feasible solution. Even if you are only receiving ticks and doing some calculations, you shouldn't be doing that on the main thread. Never block main thread which is receiving data.
Update Kite Connect python client to the latest version, it has reconnect feature.
Check out readme to know how to enable reconnect.
I have the latest version with reconnect feature and I'm even using it. But still I face this issue.
This is my reconnect call:
enable_reconnect(reconnect_interval=5, reconnect_tries=500)
Regards,
Srikanth
Did it reconnect at least once?
It shouldn't be happening, many users are already using this feature even before it was taken live.
Can you elaborate what you are doing or make a gist and paste it here?
I have some list of scrips and I try to get the streaming data from the websocket api. Below is the way I'm using it.
WS.on_connect = quoteStreamCfg
WS.on_tick = tickHdlr
WS.enable_reconnect(reconnect_interval=5, reconnect_tries=500)
WS.connect()
quoteStreamCfg:
List = my list of 170 scrips
ws.subscribe(List)
ws.set_mode(ws.MODE_FULL,List)
Generally on some days I don't face any problem, but some days I keep getting the mentioned error. One more thing I observed is that if I increase the number of scrips in my list to close to 200 I face this issue more frequently.
Regards,
Srikanth
Are you processing data of 170 ticks on the main thread?
What are you doing after you receive a tick?
I have subscribed to 170 scrips. I think the on_tick will not be called with all the 170 scrips data but only with those scrips that are changed from the last tick. Correct me if my understanding is wrong. So in any tick I will be handling some scrips data.
Please let me know if there is any latency requirement or limitation that the user software should abide to.
Regards,
Srikanth
Yes, you get data only when there is a change in data.
Even if you are subscribed to 20 to 30 scrips, single thread for processing all ticks is not a feasible solution.
Even if you are only receiving ticks and doing some calculations, you shouldn't be doing that on the main thread. Never block main thread which is receiving data.
I will spawn a new thread and unblock the main thread as you suggested. Thanks for the information.
Regards,
Srik