I'm looking to restart kite ticker connection. Can anyone suggest correct method to restart. Periodically data stops receiving from the ticker service at certain time period after 1 pm. I have subscribed around 60 instruments daily and my on_ticks function are as per the guideline. Every tick data is added to queue and the data from queue is processed in another thread. Even today the data didn't receive from ticker after 03:03 pm. Till that everything works perfect without any errors. So i decided to restart the ticker service incase of data not receiving for some time. Kindly help me with this or suggest any alternative. Note : I didn't even receive on_error or any call back function in this case. Everything seems perfect.
pykiteconnect comes with reconnect support. You don't have to do anything, library itself takes care of reconnection and re-subscribes after reconnect. You can check out documentation to know how to enable it.
Hi @sujith, I haven't overridden the default values in KiteTicker class. Whenever I gets error like network failure it reconnects itself automatically. My query is data stops receiving after some time in ticker. Can you suggest a solution for this. My ticker is started using threaded=True and all the call backs are properly assigned. Everything works perfect but only issue as i mentioned above. Also Can you tell me the maximum time delay between ticks that I receive from Kite...?
My query is data stops receiving after some time in ticker.
If the contract is active (with ticks) and there is no disconnection, this scenario won't occur. However, there might be disconnections due to errors, which would be displayed in the on_error callback. Please ensure that you have correctly added the on_error callbacks. Here is an example of the threaded ticker implementation with appropriate callbacks.
Thanks @rakeshr for your quick reply. I always subscribe weekly options in bank nifty and those are always active. I also used to receive disconnection call back error whenever there is one - from this i can surely say that i have properly set my call backs. In my case i didn't receive any. I have almost waited for more than 30 sec and even is_connected() returns true but no new ticks receiving. Any suggestion / feedback will be helpful. Thanks in advance.
I have almost waited for more than 30 sec and even is_connected() returns true but no new ticks receiving
Is it possible, to check the same contract ticks from another source? Maybe check kite web marketwatch depth during the same time, just to verify if there is a tick coming during that specific issue period. I don't see any other reason if the disconnection log shows no error, and the contract is active.
Hi @rakeshr@sujith. Again today faced the same issue - ticker stops at 11:52 and is_connected() returns TRUE. After restarting my entire server it works. I have included logger in the on_ticks method. Attached the logs along with this. Any help would be more appreciated. Subscribed Tokens - [260105, 9210626, 8974082, 18624258, 18627842, 18624002, 18621698, 9219330, 18621186, 18623234, 18619138, 8983298, 18620162, 18604290, 18601730, 9198082, 9049858, 18622722, 18862850, 18628354, 18849026, 18849282, 18845698, 18624514, 18623746, 18860290, 18611202, 18847746, 18894850, 18627330, 18826498, 18863362, 9048322, 18896642, 18618626, 18839554, 18864898, 18845186]
Can you remove onNewTicks and just keep logging for the day? Try on an alternate network also wherein you only log tick received and not do anything else. Kite Ticker is being used on our internal apps and 1000s of production Kite Connect apps, we don't see any issue from our end. If ticks stops then it will stop for everyone, not just for one connection.
You won't receive ticks if there is no change in any of the fields for the subscribed mode. You can subscribe to the higher mode(full), and inspect it.
@rakeshr Thank you for reply but i have like 182 full subscribed instruments. I am logging ticks count and sending to queue to store. The issue is on_ticks stop logging at random. I checked with different connection also. If i stop the script and rerun then i will get ticks again. So i am trying to have auto reconnection within code, but it is giving error of reactor not restartable. def on_ticks(ws, ticks): global count2 print(count2, "tick") ticks_queue.put(ticks) count2 += 1 # and below code at end while true: print(datetime.datetime.now(),": RUNNING : ", kws.is_connected()) sleep(60)
Restart ruining log ==> waiting for connection ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time)) ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time)) waiting for connection
I checked my bandwidth and there was a certain drop at that particular time, but code throw no error initially and silently stopped heartbeat ticks.
@rakeshr Thank you for support. It seems there is no direct solution to restart manually for now as reactor is using twisted-internet library. For now, I have created a fork subprocess of my main thread. Main Thread will kill the subprocess if any disconnection/noTicksWithinMin then make fresh new connection to kite.
My query is data stops receiving after some time in ticker. Can you suggest a solution for this. My ticker is started using threaded=True and all the call backs are properly assigned. Everything works perfect but only issue as i mentioned above.
Also Can you tell me the maximum time delay between ticks that I receive from Kite...?
I don't see any other reason if the disconnection log shows no error, and the contract is active.
After restarting my entire server it works. I have included logger in the on_ticks method.
Attached the logs along with this.
Any help would be more appreciated.
Subscribed Tokens - [260105, 9210626, 8974082, 18624258, 18627842, 18624002, 18621698, 9219330, 18621186, 18623234, 18619138, 8983298, 18620162, 18604290, 18601730, 9198082, 9049858, 18622722, 18862850, 18628354, 18849026, 18849282, 18845698, 18624514, 18623746, 18860290, 18611202, 18847746, 18894850, 18627330, 18826498, 18863362, 9048322, 18896642, 18618626, 18839554, 18864898, 18845186]
Kite Ticker is being used on our internal apps and 1000s of production Kite Connect apps, we don't see any issue from our end. If ticks stops then it will stop for everyone, not just for one connection.
def on_ticks(ws, ticks):
global count2
print(count2, "tick")
ticks_queue.put(ticks)
count2 += 1
# and below code at end
while true:
print(datetime.datetime.now(),": RUNNING : ", kws.is_connected())
sleep(60)
15507 tick
15508 tick
2024-06-12 11:41:31.941111 : RUNNING True
15509 tick
15510 tick
15511 tick
.
.
.
15590 tick
15591 tick
15592 tick
15593 tick
2024-06-12 11:42:31.967035 : RUNNING True
2024-06-12 11:43:31.985185 : RUNNING True
2024-06-12 11:44:31.999591 : RUNNING True
2024-06-12 11:45:32.032321 : RUNNING True
2024-06-12 11:46:32.042115 : RUNNING True
15507 tick
15508 tick
2024-06-12 11:41:31.941111 : RUNNING True
15509 tick
15510 tick
15511 tick
.
.
.
15590 tick
15591 tick
15592 tick
15593 tick
2024-06-12 11:42:31.967035 : RUNNING True
2024-06-12 11:43:31.985185 : RUNNING True
2024-06-12 11:44:31.999591 : RUNNING True
2024-06-12 11:45:32.032321 : RUNNING True
2024-06-12 11:46:32.042115 : RUNNING True
2024-06-12 11:47:32.055233 : RUNNING True
2024-06-12 11:48:32.081261 : RUNNING True
PS E:\Python\p11 kiteconnect 1> ^C
Restart ruining log ==>
waiting for connection
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket opening handshake timeout (peer did not finish the opening handshake in time))
waiting for connection
I checked my bandwidth and there was a certain drop at that particular time, but code throw no error initially and silently stopped heartbeat ticks.
For now, I have created a fork subprocess of my main thread. Main Thread will kill the subprocess if any disconnection/noTicksWithinMin then make fresh new connection to kite.