Update Tokens during program run in WebSockets

razcads
Hi
My use case is below
I have a program that initiates WS with a list of tokens and performs a number of actions on each tick. During execution I need to add additional tokens to this the tick. How can this be done? Just updating the tokens doesn't update the tick list.
Is this even possible or do I need to start another WS call for the new tokens which is a dirty way to do it. Hope I am making sense. Let me know. Thanks.

Pseudo Code:
def main()
def on_tick(tick,ws):
#Do a lot of things based on tick..
# While doing some check in a "new thread" i find that i need tick data for a new script
# How can i update the tick / tokens to let WS know that a new set of tokens has arrived and
# real time ticks are needed against this new set?

def on_connect(ws):
ws.subscribe(tokens)
ws.set_mode(ws.MODE_LTP, tokens)

kws.on_tick = on_tick
kws.on_connect = on_connect
  • sujith
    Hi,
    You can call subscribe again with new tokens and that will send a text message to Kite Ticker again with new tokens and you will get ticks after that, just like earlier tokens.
    Subscribing to new tokens will not result in unsubscribe of old tokens.
  • razcads
    Great!
    What if I have to remove a specific token? Can I unsubscribe a single token while other tokens continue to be subscribed?

  • sujith
    Yes, you can unsubscribe for a single token.
  • razcads
    Perfect! Thanks a ton!
This discussion has been closed.