Unsubscribe Token is not working

Avatar
Hi,

Even after sending Unsubscribe(string[] Tokens) request I keep getting data for the same. This is a bug. Please have a look.
  • tonystark
    Hi @Avatar,

    How many tokens are you subscribing simultaneously? Can you give example list of tokens to reproduce this issue?
  • Avatar

    Kindly have a look. I just subscribed to one symbol only NIFTY17NOVFUT.
    Data keeps coming even after I send a Unsubscribe request.
  • tonystark
    Hi @Avatar,

    It seems to be working fine from our side. Can you post the code snippet you are using to unsubscribe the token?
  • Avatar
    Avatar edited November 2017
    public void UnSubscribeTicker(string[] arrayTokensToUnSubscribe)
    {
    ticker.UnSubscribe(arrayTokensToUnSubscribe);
    }

    public void UnSubscribe(string[] Tokens)
    {
    string msg = "{\"a\":\"unsubscribe\",\"v\":[" + String.Join(",", Tokens) + "]}";
    if (_debug) Console.WriteLine(msg);

    if (IsConnected)
    _ws.Send(msg);
    foreach (string token in Tokens)
    {
    if (token != null)
    {
    if (_subscribedTokens.ContainsKey(token))
    {
    _subscribedTokens.Remove(token);
    Console.WriteLine("Token UNsubscribed : " + token);
    }
    }
    }
    }
  • tonystark
    Hi @Avatar,

    This code looks fine. There must be some issue in the way you call UnSubscribeTicker function.
  • Amol_Kadam
    Amol_Kadam edited September 2019
    @tonystark

    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
  • Amol_Kadam
    Amol_Kadam edited September 2019
    @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.
Sign In or Register to comment.