Can someone let me know how do you modify your websocket token subscription to the token on the fly, basically unsubscribing and subscribing to new tokens? I could not find one, hence asking.
Not asking for exact code, but any pointers to which code blocks should go where would be helpful or a thread which discusses this topic.
Went through few threads and came up with this, covers as a boiler plate for not having any logic inside main on_ticks, also covered how to unsubscribe and subscribe to new tokens if needed. All worker methods inside the while loop, trade logic and other methods called under on_ticks under while loop.
Is there a way to on_connect without subscribing at the firs time, I would like to connect, but subscribe to the instrument_token later based on the trade logic to only the instruments needed.
You can call it any number of times on the fly.
Went through few threads and came up with this, covers as a boiler plate for not having any logic inside main on_ticks, also covered how to unsubscribe and subscribe to new tokens if needed. All worker methods inside the while loop, trade logic and other methods called under on_ticks under while loop.
Can you guys confirm if this looks fine?
Is there a way to on_connect without subscribing at the firs time, I would like to connect, but subscribe to the instrument_token later based on the trade logic to only the instruments needed.
I even tried this:
tokens0 = []
def on_connect(ws, response):
ws.subscribe(tokens0)
ws.set_mode(ws.MODE_FULL, tokens0)
and tried this:
tokens0 = [10985474]
def on_connect(ws, response):
ws.subscribe(tokens0)
ws.set_mode(ws.MODE_FULL, tokens0)
ws.unsubscribe(tokens0)
But, does not work
Do I need to do on_connect again inside While True?
on_connect is just a callback called when on_connected event is triggered.