No, as websocket is a single long standing connection. You just need access token to start websocket.
However,you won't be able to make any other api calls if access token expires.
@SRIJAN Say I established a websocket connection, everything going smooth, next day, after access_token which I used to create connection in 1st place expires, as I understand, connection will still be smooth. My query is, if there's a connection error next day, when access token has changed, does auto reconnect work as expected? or will I need to pass in new access token to create websocket object again and connect again?
You will need a valid access token to connect to websocket every time.
So,reconnection won't work in case access token expires. It will give error 403 .
Hence,if you are confident there will be no disconnections,then only continue without generating new access token every morning.
@SRIJAN Now, I'm not sure how should I handle connection drop at some time after access token was expired and updated in global variable, is this correct way to go about it?
Yeah,it looks ok. Just one thing you have to add.
Before initializing new KiteTicker instance inside on_close, use ws.stop_retry() ,otherwise the initial websocket thread will continue running and utilising memory(and also printing the error messages ). Also, don't forget to assign callbacks again.
How does this defeat the purpose of auto reconnection??
Auto reconnection just tries to connect with the access_token passed when initializing KiteTicker,to the websocket.
If access token expires,the only way now is to initialize new KiteTicker instance with valid access token and then connect to websocket.
However,you won't be able to make any other api calls if access token expires.
Say I established a websocket connection, everything going smooth, next day, after access_token which I used to create connection in 1st place expires, as I understand, connection will still be smooth.
My query is, if there's a connection error next day, when access token has changed, does auto reconnect work as expected?
or will I need to pass in new access token to create websocket object again and connect again?
So,reconnection won't work in case access token expires. It will give error 403 .
Hence,if you are confident there will be no disconnections,then only continue without generating new access token every morning.
I'm glad I asked this query, this is very valuable info. Even though I have everything hosted on AWS, still once a week i was seeing 403, which was annoying, I thought why is auto reconnect not working!
Now, I'm not sure how should I handle connection drop at some time after access token was expired and updated in global variable, is this correct way to go about it?
def on_close(ws, code, reason):
....ticks_logger.info(f"Connection Closed !! Reason: {reason}")
....global kws, api_key, access_token
....if kws==None or kws.is_connected()==False:
........kws = KiteTicker(api_key, access_token)
........kws.connect(threaded=True)
Isn't this defeating the purpose of auto re connection?
Before initializing new KiteTicker instance inside on_close, use ws.stop_retry() ,otherwise the initial websocket thread will continue running and utilising memory(and also printing the error messages ). Also, don't forget to assign callbacks again.
How does this defeat the purpose of auto reconnection??
Auto reconnection just tries to connect with the access_token passed when initializing KiteTicker,to the websocket.
If access token expires,the only way now is to initialize new KiteTicker instance with valid access token and then connect to websocket.
Thank you