How to add new instrument without closing the connection? I am using the python client.
I am currently creating a thread where on new instrument addition I am connecting again. Is there any other way I can handle this?This would take some time for the new data of the subscribed scrip to come up.
You can connect to client with option threaded=True which opens the connection in separate thread and main thread can be used to subscribe to token dynamically. Here is an example
# wait to establish a connection import time time.sleep(5)
# Wait for user input and block the current thread while True: token = input("Enter token to subscribe : ") print("Subscribe to ", token) kws.subscribe([token])
Thanks @vivek I did the same think with eventlet but maybe I will refactor to this.One more request the tickdata comes as an array. The problem is with multiple instrument streaming at one time there has to be loop through array to get the data/instruemnt name.This is a performance overhead. Instead if the payload is in dictionary then search time for key:value is much less compared to array search.I understand this might be very trivial but to imagine a situation where I stream 100 instrument and I expect each instrument has its own handler,then after I receive the tickdata I have to loop through every instrument to invoke the handler. This is costly.
@gully Yeah you got a point, If you wish you can write a patch for it and create a pull request else open an issue in github and we will try to incorporate when we get time .
threaded=True
which opens the connection in separate thread and main thread can be used to subscribe to token dynamically. Here is an example