Java client is what I am using... Also why should it be client centric? When I use normal Websocket apis to connect right after disconnectoin,it fails..i wait for 2 seconds after which I connect and subscribe the tokens,but it fails..what is going on?
@pinkpanther, The feature is not client centric but my answer is. In java, you can setTimeIntervalForReconnection(). It is based on user's input but minimum value is 5 seconds. You need use OnConnected event for the subscription. Check out usage example here.
Let me say I am using no client ..but just plain websockets,lets say choice of language is perl/julia and ondisconnection I am connecting again,without any waiting time,logically it should work right?But its not working
@pinkpanther, When there is an abrupt change in network or disconnection. OnDisconnect is not called immediately. Hence we have a different mechanism for reconnection. Kite Connect client keeps checking every second if tick arrived, if there is no tick for 5 seconds then it will reconnect.
@sujith thanks for the explanation...i am not using kiteconnect..but normal REST APIs therefore the check that you mentioned for 5 seconds doesnt hold valid in my code. For me what i am doing is if i there is a disconnection, i am reconnecting again at the same second or after 1 second...it should work right?
@pinkpanther, If you are looking for uninterrupted Kite Ticker then you need to implement reconnection same way as we have implemented. You must be expecting onDisconnect event when there is disconnection but it is not called. Hence we added a different mechanism for reconnection.
# Callback for tick reception. def on_tick(tick, ws): print tick
# Callback for successful connection. def on_connect(ws): # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe(totalTokens)
# Set RELIANCE to tick in `full` mode. ws.set_mode(ws.MODE_FULL, [738561])
def on_disconnect(ws): print "Connection is dropped...subscribing again" on_connect()
# Infinite loop on the main thread. Nothing after this will run. # You have to use the pre-defined callbacks to manage subscriptions. kws.connect()
This is what i am doing..plainly connecting again when there is disconnection..but this doest work..I get that the connection happens and the ticks are subscribed..but nothing comes..
Hi @pinkpanther, I would suggest using our reconnect feature provided by new beta pykiteconnect version as connect inside disconnect is not a reliable way for reconnection. You can check out this thread for more information.
What KiteConnect client are you using?
Also why should it be client centric?
When I use normal Websocket apis to connect right after disconnectoin,it fails..i wait for 2 seconds after which I connect and subscribe the tokens,but it fails..what is going on?
The feature is not client centric but my answer is.
In java, you can setTimeIntervalForReconnection(). It is based on user's input but minimum value is 5 seconds.
You need use OnConnected event for the subscription. Check out usage example here.
When there is an abrupt change in network or disconnection. OnDisconnect is not called immediately. Hence we have a different mechanism for reconnection.
Kite Connect client keeps checking every second if tick arrived, if there is no tick for 5 seconds then it will reconnect.
For me what i am doing is if i there is a disconnection, i am reconnecting again at the same second or after 1 second...it should work right?
If you are looking for uninterrupted Kite Ticker then you need to implement reconnection same way as we have implemented.
You must be expecting onDisconnect event when there is disconnection but it is not called. Hence we added a different mechanism for reconnection.
from kiteconnect import WebSocket
# Initialise.
kws = WebSocket("your_api_key", "your_public_token", "logged_in_user_id")
totalTokens=[]
# Callback for tick reception.
def on_tick(tick, ws):
print tick
# Callback for successful connection.
def on_connect(ws):
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe(totalTokens)
# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [738561])
def on_disconnect(ws):
print "Connection is dropped...subscribing again"
on_connect()
# Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect
kws.on_disconnect=on_disconnect
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
This is what i am doing..plainly connecting again when there is disconnection..but this doest work..I get that the connection happens and the ticks are subscribed..but nothing comes..
I would suggest using our reconnect feature provided by new beta pykiteconnect version as connect inside disconnect is not a reliable way for reconnection.
You can check out this thread for more information.