Hi, So I was wondering how can I check if I have received a tick in last "n" seconds. Like after calling kws.connect(), main thread is blocked and suppose we just print the tick data, but sometimes during the day, kws.on_tick() hangs and dont print tick data or any error while keeping the main thread blocked. I want to have a wrapper which would be checking that we have received a tick data in last "n" seconds and if not, re-run the kws.connect() and restart the websocket connection. How would I do that?
Hi, There is no method or API to check, if you have received ticks or not. KiteTicker is just a simple websocket channel which keeps broadcasting data once it gets data from exchange. If you subscribe for it you will get it. Even if you don't get ticks, you must be getting heartbeat ticks, which is confirmation that connection is alive. I would suggest, check for these heartbeat ticks when it hangs. If you are not getting, then check your implementation.
@hpahel A fairly simple approach is to add a flag to a redis list along with a timestamp. Have a separate 'watch' process keep a blocking get (in a loop) on the redis queue with a finite timeout watching for this flag, and if the 'monitor' blocking get does get timed out, go ahead and do a kill/restart routine.
You would need to create a mechanism to place process ID's and the like also in some store (could be redis again) so that your monitor knows which process to kill.
I get ticks for 30 mins then it hangs.. i dont get any ticks after that ... how can i check the tick heartbeat. im using python 2.7 , i cannot restart the code it will mess my logic.
There is no method or API to check, if you have received ticks or not. KiteTicker is just a simple websocket channel which keeps broadcasting data once it gets data from exchange. If you subscribe for it you will get it. Even if you don't get ticks, you must be getting heartbeat ticks, which is confirmation that connection is alive.
I would suggest, check for these heartbeat ticks when it hangs. If you are not getting, then check your implementation.
You would need to create a mechanism to place process ID's and the like also in some store (could be redis again) so that your monitor knows which process to kill.
im using python 2.7 , i cannot restart the code it will mess my logic.
Just add log in on_tick to check heartbeat tick.