Can somebody explain how to read streaming data from web socket object?, I'm able to instantiate web socket class, connect(threaded=True), subscribe instrument and set mode.Just didn't understand succeed in reading streaming data.
You need to use option threaded=True incase you don't want to block your main thread and run WebSocket in different thread than your main thread. You can read about threading in python here.
Thanks for the prompt reply, my object oriented programming skills are bit rusty, from the above suggested example can u pl further explain the following :
kws.on_tick = on_tick kws.on_connect = on_connect
as per my understanding "kws.on_tick/on_connect" is an instance variable,"on_tick" is an user defined function, what happening in "kws.on_tick = on_tick"
@jvshk78tradeon_tick function is a user defined callback and when you assign it like this kws.on_tick = on_tick then on_tick function will be called whenever there is a tick received with two params tick and ws where tick is the array of ticks object and ws is the WebSocket object.
@Vivek I think I'm now understanding the complete picture:
1) "kws.on_tick" is used as parameter in some mysterious method defined in WebSocket class. 2)"kws.on_tick = on_tick" basically makes "kws.on_tick" a pointer to "on_tick ()" function which is going into whichever function is taking in "kws.on_tick"
@soumyadeep Thats an example which shows you that you can change mode or subscribe to any other instruments while websocket is running in different thread. Its just an basic example and you might be doing the stuffs related to your app logic.
You can try this example - https://gist.github.com/vividvilla/10a5ca6e5a479a904e0fdb66dfd6a108
You need to use option
threaded=True
incase you don't want to block your main thread and run WebSocket in different thread than your main thread. You can read about threading in python here.Thanks for the prompt reply, my object oriented programming skills are bit rusty, from the above suggested example can u pl further explain the following :
kws.on_tick = on_tick
kws.on_connect = on_connect
as per my understanding "kws.on_tick/on_connect" is an instance variable,"on_tick" is an user defined function, what happening in "kws.on_tick = on_tick"
on_tick
function is a user defined callback and when you assign it like thiskws.on_tick = on_tick
thenon_tick
function will be called whenever there is a tick received with two paramstick
andws
where tick is the array of ticks object and ws is the WebSocket object.You can read more about callbacks here - https://stackoverflow.com/questions/824234/what-is-a-callback-function
Thanks for the much needed guidance,
kws
.1) "kws.on_tick" is used as parameter in some mysterious method defined in WebSocket class.
2)"kws.on_tick = on_tick" basically makes "kws.on_tick" a pointer to "on_tick ()" function which is going into whichever function is taking in "kws.on_tick"