Unable to unsubscribe the symbol in WebSocket and close the connection
-
Hi I am unable to unsubscribe the symbol when i don't need it. Even after unsubscribing it using sws.unsubscribe(correlation_id, mode, token_list) and trying to close the connection using sws.close_connection(), it doesn't close the connection but the symbol gets re-subscribe.
What is the issue?for more details sharing the code.
global correlation_id, mode, sws
AUTH_TOKEN = credential.range('b8').value angelapikey = credential.range('b4').value feed_token = credential.range('b7').value client_code = credential.range('b2').value correlation_id = "option_live_data" action = 1 mode = 1 sws = SmartWebSocketV2(AUTH_TOKEN, angelapikey, client_code, feed_token) token_list = [{"exchangeType": 1, "tokens": [token_Nifty,token_Bank,token_Fin,token_Mid]}] token_Nifty = "26000" token_Bank = "26009" token_Fin = "26037" token_Mid = "26074" def on_data(wsapp, message): # print("Ticks: {}".format(message)) token = message['token'] last_price = message['last_traded_price'] last_price = last_price/100 print(last_price) def on_open(wsapp): print("\n------Options Live LTP subscribed------") sws.subscribe(correlation_id, mode, token_list) def on_error(wsapp, error): print(error) def on_close(wsapp): print("Close") sws.on_open = on_open sws.on_data = on_data sws.on_error = on_error sws.on_close = on_close threading.Thread(target = sws.connect).start() def ws_disconnect(): print("\n------ Unsubscribed Options ------") sws.unsubscribe(correlation_id, mode, token_list) sws.close_connection()
-
Hello @namit
@chetansuri is already replied to your concern
Regards,
SmartAPI Team -
@Deepak9097 websocket connection is for continuous data and you can use it as it is. you don't want to run it every 15 seconds just to get 1 tick of data. You can have your analysis setup based on 15 seconds interval or so.
-
@admin Have you find any solution ?
I want to make Websocket connection with interval of 10-15 sec.
How's this possible? - topic:timeago_earlier,about a month
-
@Moderator_2 Have you analysed it yet?
- topic:timeago_earlier,about a month
-