Get my subscription list in websocket

vishnux
I have made successful handshake using websocket , I use following code

function onTick(ticks) {
console.log("Ticks", ticks);
}
function onConnect() {
ticker.subscribe([53429767]);
ticker.setMode(ticker.modeFull, [53429767]);
}

Now how do I know if I am subscribed to it , what if I had lots of subscriptions ? How to remove them all
  • shortwire
    You need to maintain a local datastructure of your subscriptions.
    e.g after the below lines:
    ticker.subscribe([53429767]);
    ticker.setMode(ticker.modeFull, [53429767]);

    you can add the subscription to your local datastructure
    allSubscriptions.Add(53429767);

    In this case, allSubscriptions will be a list of Unsigned Long integers.

    When you require to know what symbols are subscribed, you need to just loop through allSubscriptions list
  • vishnux
    So whenever I initiate websocket I must re-subscribe to certain stocks to receive its ticks ?? These are not stored in zerodha ?

    also is there any callbacks if my subscription is successful ?
  • shortwire
    If you are using KiteConnect official C# library, its already there:
    private void _onConnect()
    {
    // Reset timer and retry counts and resubscribe to tokens.
    _retryCount = 0;
    _timerTick = _interval;
    _timer.Start();
    if (_subscribedTokens.Count > 0)
    ReSubscribe();
    OnConnect?.Invoke();
    }

    In the above case, _subscribedTokens is a dictionary
    private Dictionary _subscribedTokens;

    You can get your subscribed tokens here and in case of disconnection and reconnection, the old subscriptions are picked up from this dictionary and re-subscribed.
Sign In or Register to comment.