Hello Experts, This might be a noob question (so, apologies), but I am trying to find a way on how can I update the ticker subcriptions while the ticker is running without stopping and restarting it. I don't have anything special in subscription, this is how I subscribe it. == def on_connect(ws, response): logging.debug("Successfully connected. Response: {}".format(response)) print(tokens) ws.subscribe(tokens) == I tried doing " ws.subscribe(tokens)" in on_ticks (with a different token list), but it doesn't seem to work. Any suggestions?
Hello @SRIJAN . Thanks! I had a typo, because of which "tokens" didn't have a right value. However, in your opinion it's okay to do this in on_tick? or there is a better place to update the subscribed tokens? in this implementation, it seems subscribe method is being called a lot of times (yes, I've added the code to ensure that it's not called every tick, but still it's called every 30 seconds), is there any other way to do it? where I can use subscribe again, only after tokens are really updated.
Yeah, that's obvious, but it might not work in scenarios where conditional evaluation is slow, example is my use case where I want to subscribe to tokens of my current positions. Which means, I have to call a webservice to get the current positions, which takes time, and would cause on_tick to fail (I hope my understanding that on_ticks is time sensitive is correct)
https://kite.trade/forum/discussion/4875/web-socket-dynamic-subscription
==
def on_ticks(ws, ticks):
if tokens!=current_position_tokens
ws.subscribe(current_position_tokens)
tokens=current_position_tokens
==
where current_position_tokens was updated elsewhere outside on_ticks:
Thanks for your help as always @SRIJAN !