My socket connection dies some times and in order to start it back i am using a the following code. But it doesn't seem to work . It give me the following error:
ERROR:websocket:error from callback >: 'error' object has no attribute 'reconnect'
Here is my code: # Callback for tick reception. def on_tick(tick, ws): global tick_data tick_data = pd.DataFrame(json_normalize(tick))
# Callback for successful connection. def on_connect(ws): # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe([6401,738561,3050241,2953217,895745,3930881,1270529,41729,415745,3721473,779521,3677697,5215745])
# Set RELIANCE to tick in `full` mode. #ws.set_mode(ws.MODE_FULL, [738561]) def on_close(ws): ws.reconnect()
def on_error(ws): ws.reconnect()
#initialize websocket object kws = WebSocket(api_key, data["public_token"],data["user_id"]) # Assign the callbacks. kws.on_tick = on_tick kws.on_connect = on_connect kws.on_close = on_close kws.on_error = on_error # Infinite loop on the main thread. Nothing after this will run. # You have to use the pre-defined callbacks to manage subscriptions. kws.connect(threaded=True)
Could you plese tell me whats the issue. I have the latest kite connect library
Hi @kaushikvelingkar, Reconnection using on_error is not reliable as the event is not triggered when there is an abrupt change in the network. Install pykiteconnect v3.5 to use reconnection feature. If you already have kiteconnect then upgrade it using the following command,
pip install --upgrade kiteconnect
To enable reconnection use this, kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)
Reconnection using on_error is not reliable as the event is not triggered when there is an abrupt change in the network. Install pykiteconnect v3.5 to use reconnection feature.
If you already have kiteconnect then upgrade it using the following command,
pip install --upgrade kiteconnect
To enable reconnection use this,
kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)
For more information check out readme