algo2t / alphatrade

Python APIs for SAS Online Alpha Trade Web platform for creating algo trading using python
https://algo2t.github.io/alphatrade
MIT License
44 stars 24 forks source link

Right way to stop data streaming #7

Closed qFactorin closed 2 years ago

qFactorin commented 3 years ago

Hi, could you please give some guidance on right way to stop websocket stream.

algo2t commented 3 years ago

You can try to use ws.close() or ws.stop() , I have not tried it myself but read about it. You can implement a try catch for Exception KeyboardInterrupt

dccgarch commented 2 years ago

i dont want to stream data all the time.. i just want to read ltp and stop the streaming .. how to go about it? I dont think ws.stop will work here

algo2t commented 2 years ago

@dccgarch subscribe and unsubscribe a scrip token is the best way. keep stream running

algo2t commented 2 years ago

Check documentation here for subscribe and here for unsubscribe

dccgarch commented 2 years ago

i did subscribe and unsubscibe and it kept streaming ..I got the ltp printed in the middle.. so i guess i am doing the right way which is exactly similar to what you have suggested. I was just wondering would you be able to demonstrate something like using sqlite and store the streaming data in a db and then possibly resample the data to form candle. SO here you get both ltp and real time candles too