I am calling below implementation and passing the token array but somehow it is not unsubscribing the token. After unsubscribing a am again subscribing it using subscribe90 method but is is providing all the token since unsubscribe didn't actually removed the tokens.
Could you please suggest the resolution?
In def on_connect i am setting the wsobject. Is it right way to initialize the ws?
def on_connect(self, ws, response): self.ws= ws print("Successfully connected. Response: {}".format(response)) ws.subscribe(self.tokensArray) ws.set_mode(ws.MODE_LTP, self.tokensArray) print("Subscribe to tokens in Full mode: {}".format(self.tokensArray)) # return render_template('index2.html')
def unsubscribe(self, instrument_tokens): """ Unsubscribe the given list of instrument_tokens. - `instrument_tokens` is list of instrument_tokens to unsubscribe. """ try: self.ws.sendMessage( six.b(json.dumps({"a": self._message_unsubscribe, "v": instrument_tokens})) ) for token in instrument_tokens: try: del(self.kws.subscribed_tokens[token]) print("Delete Completed") except KeyError: pass return True except Exception as e: self.kws.close(reason="Error while unsubscribe: {}".format(str(e))) raise
def subscribe(self, instrument_tokens): """ Subscribe to a list of instrument_tokens. - `instrument_tokens` is list of instrument instrument_tokens to subscribe """ try: self.ws.sendMessage( six.b(json.dumps({"a": self._message_subscribe, "v": instrument_tokens})) ) for token in instrument_tokens: self.kws.subscribed_tokens[token] = self.kws.MODE_LTP return True except Exception as e: self.kws.close(reason="Error while subscribe: {}".format(str(e))) raise
@Vivek could you please helphere. I want to close my kite ticker connection in threaded environment plus these above mentioned subscribe and unsubscribe is not taking place.
How many tokens are you subscribing simultaneously? Can you give example list of tokens to reproduce this issue?
Kindly have a look. I just subscribed to one symbol only NIFTY17NOVFUT.
Data keeps coming even after I send a Unsubscribe request.
It seems to be working fine from our side. Can you post the code snippet you are using to unsubscribe the token?
This code looks fine. There must be some issue in the way you call
UnSubscribeTicker
function.I am calling below implementation and passing the token array but somehow it is not unsubscribing the token.
After unsubscribing a am again subscribing it using subscribe90 method but is is providing all the token since unsubscribe didn't actually removed the tokens.
Could you please suggest the resolution?
In def on_connect i am setting the wsobject. Is it right way to initialize the ws?
def on_connect(self, ws, response):
self.ws= ws
print("Successfully connected. Response: {}".format(response))
ws.subscribe(self.tokensArray)
ws.set_mode(ws.MODE_LTP, self.tokensArray)
print("Subscribe to tokens in Full mode: {}".format(self.tokensArray))
# return render_template('index2.html')
def unsubscribe(self, instrument_tokens):
"""
Unsubscribe the given list of instrument_tokens.
- `instrument_tokens` is list of instrument_tokens to unsubscribe.
"""
try:
self.ws.sendMessage(
six.b(json.dumps({"a": self._message_unsubscribe, "v": instrument_tokens}))
)
for token in instrument_tokens:
try:
del(self.kws.subscribed_tokens[token])
print("Delete Completed")
except KeyError:
pass
return True
except Exception as e:
self.kws.close(reason="Error while unsubscribe: {}".format(str(e)))
raise
def subscribe(self, instrument_tokens):
"""
Subscribe to a list of instrument_tokens.
- `instrument_tokens` is list of instrument instrument_tokens to subscribe
"""
try:
self.ws.sendMessage(
six.b(json.dumps({"a": self._message_subscribe, "v": instrument_tokens}))
)
for token in instrument_tokens:
self.kws.subscribed_tokens[token] = self.kws.MODE_LTP
return True
except Exception as e:
self.kws.close(reason="Error while subscribe: {}".format(str(e)))
raise