Hi .. Any one kindly help me.. In between the market hours i want to close and connect to the websocket. Below is the sample code. def on_ticks(ws,ticks): //Some logic kws.close() time.sleep(1) kws.connect()
But sometimes in between i am getting the error as "429 - TooManyRequests". How to avoid this error. Is there is any way to cleanly close the connection? Thanks in advance.
Hi @sujith@rakeshr after implementing above code still getting the error as
kiteconnect.ticker - ERROR - Connection error: 1006 - connection was closed uncleanly (WebSocket closing handshake timeout (peer did not finish the opening handshake in time))
Can you advise me to close the connection gracefully.
I cant understand why you put kws.stop() , kws.conect() inside on_ticks() ? Don't put any tick calculations inside on_ticks() it will block your ticks if you do that.
Hi @sujith thanks for the response. PFA. Is this is the correct way.Please guide me if i need to modify anything.
kws.stop()
,kws.conect()
insideon_ticks()
?Don't put any tick calculations inside on_ticks() it will block your ticks if you do that.
try this:
def on_close(ws, code, reason):
ws.stop()
Include this thread when connecting with the kite ticker ,
kws.connect(threaded=True)
instead of justkws.connect()