On this film, we stream inventory present market particulars from polygon.io making use of websockets and our Alpaca API important. We join making use of the 2 wscat and a Python websocket consumer.


Purchase Me a Espresso: https://buymeacoffee.com/parttimelarry
Twitter: https://twitter.com/PartTimeLarry
Internet-site: https://hackingthemarkets.com
Supply Code: https://github.com/hackingthemarkets


36 thoughts on “Genuine-Time Streaming Stock Market Particulars with Python and Websockets”

  1. I was wondering whether we can use this real-time tick-by-tick data to create a strategy and if yes then please make a video on this as to writing real-time data into a CSV or a DB then creating strategies with it.

  2. Larry, great explanation! A simple question, if you do not mind answering – would it be possible to live plot websocket stream within the same python code (same file that opens websocket), so it just pops up a simple dynamic plot while streaming (ie without saving to CSV, reading back etc)?

  3. Thank god finally I found a tutorial about WebSocket streaming of data. I am trying to stream data through IBKR. After modifying the script I am getting the following error "ModuleNotFoundError: No module named 'websocket'' " Thanks a lot.

  4. Hi Larry, thanks for the great video. Just one question, in the python example, you called ws.send() first for authentication then called ws.send() again for subscribing to quotes. I'm wondering if the ws.send() function async? Should we wait for the first ws.send() success then send the second one?

  5. Hey Larry, how can i access the keys within the dictionary if the dictionary is inside of a list? I've been trying to access the bid and ask prices to use them in my strategy but I just can't find a way to pull them from the dictionary..

  6. LOVE this tutorial. I am having an issue though, any suggestions? When I go to authenticate my API key I get a response: zsh: command not found: action:subscribe,params:MYAPIKEY

  7. but how do you put this live data into a dataframe so that you can place orders on the close or open of a candle? can you make a video on putting live websocket data into a pandas dataframe?

  8. Hi , I am getting authentication failed message. i have tried generating keys from Alpaca but it is giving same message, what may be the issue ?

    C:UsersAdministratorDesktopWebsocket>python app.py


    reaceived a message

    [{"ev":"status","status":"connected","message":"Connected Successfully"}]

    reaceived a message

    [{"ev":"status","status":"auth_failed","message":"authentication failed"}]

  9. Hey Larry, thanks for the amazing video. While running the script, I get a message, [{"ev":"status","status":"max_connections","message":"Maximum number of connections exceeded."}]. Is this because I'm using my Paper Trading API key? I have a funded alpaca account but am using the paper trading API key to test some algos first. Any suggestions? thanks

  10. Hi Larry, following step by step and trying multiple different examples of connecting to the alpaca-polygon websocket api I do not get a response within PyCharm or when I run my code within the terminal. However I know I can connect to the websocket through the terminal directly using wscat, trouble shooting to make sure my credentials do indeed work i get exactly the response I should get and a working subscribed stream,; when I run this cloned script with the modified tickers and API key to my own it simply inputs and jumps to the next python command as if nothing runs, it appears I am not making the initial connection? Any ideas? I simply cannot get an answer anywhere I search the internet. Any direction helps! Love your tutorials they are very helpful and the best I have seen educational wise in the algo-trading world.



  11. Hi Larry, awesome video. Could you please make a video for the same through TD Ameritrade. As in I how to code in python to grab live streaming data through TDA API. Most people use TDA and that would be greatly helpful.
    Thanks for all your videos.

  12. Hi Larry, perhaps you have an answer, I cannot authenticate via the terminal. Thanks for your help.
    > (base) MacBook-Pro-GJ:~ gj$ wscat -c wss://alpaca.socket.polygon.io/stocks

    Connected (press CTRL+C to quit)

    < [{"ev":"status","status":"connected","message":"Connected Successfully"}]

    > {"action":"auth","params":"I use my key here"}

    < [{"ev":"status","status":"auth_failed","message":"authentication failed"}]

Leave a Reply

Your email address will not be published. Required fields are marked *