Real-Time Streaming Stock Market Data with Python and Websockets
HTML-код
- Опубликовано: 21 авг 2024
- In this video, we stream stock market data from polygon.io using websockets and our Alpaca API key. We connect using both wscat and a Python websocket client.
github.com/hac...
Buy Me a Coffee: buymeacoffee.c...
Twitter: / parttimelarry
Website: hackingthemark...
Source Code: github.com/hac...
Awesome video Larry - You have a real talent of explaining these concepts and getting people up and running quickly using your examples and tutorials. Keep it up.
Thanks much more to come!
Only place where I could find how to properly communicate with a websocket. This is precisely what I needed to know! thank you very much.
Fantastic video. Very educational. appreciate the time taken to make these videos and make the content easy to use. Just started working with the Alpaca API last week so having the Polygon data feeding into it will be a nice complement. Keep the videos coming please.
You are part of the reason I’m becoming dev😅🤟🏼 I don’t know anything but you explain this stuff so professionally! Where’s the new content? Hope all is well❤️👊🏼
Thanks man! Hope you keep it up, love these kinds of comments. I've been busy with some projects lately, so have been on a pause. I still think about making new videos all the time though...hopefully soon.
Great video. You're a good explainer/communicator. I recommend putting a light source in front of your face so that we can see you.
Thanks, I have a much better setup in my more recent videos :). Tool me a while to get my resolution and recording/editing setup right.
Awesome Video! I am amazed that at this point you only have 6K Views
Great video! Simple and to the point in less than 15 minutes.
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.
Awesome Tutorial this Series will be very nice
Thanks!
Super interesting content, waiting for next.
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.
Your lecture helps me a lot, thank you.
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?
Why aren't you using asyncio library in this video? Other vidoes explaining websockets on python are using asyncio but don't know why it is needed
Great channel. Been trading recently, and trying to build some Python apps to find setups.
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.
Yea would love to see that too. How to write real time data to a database.
Thanks so much for this video man
Thank you this.
Great tutorial, thanks 👍
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
Great video thank you! Can you do another one on how to handle websocket with a sync please
Thanks Boss
Amazing!
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)?
Great video! what is the most accurate realtime stock data library for Python? (Ideally with the best price)
Hi Larry, thanks for all of the information in this video. Do you have any suggestions for how i can extract what the *exact time* the "high tick" happened at, and the exact time of the low tick?
thank you for your wonderful tutorials. Any chance that the connection fails if you are using paper account?
Hey, in this video I used an API key from my paper account. Did you give it a try and have issues? There is always a chance a connection can fail. If you are sure your code is correct, then you can just have the script wait a few seconds and retry the connection.
I was having an issue opening a connection to the Websocket....but I finally figured out what was wrong.
What I first did was add an ,on_error=on_error, in the parenthasis of WebSocketApp().
Then I created an on_error function that would print out the error.
def on_error(ws, error):
print(error)
This gave me the following error.... [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
After some googling of this error, I found something that said I needed to run:
Applications/Python\ 3.8/Install\ Certificates.command
After I did this, I was able to open up a connection to a Websocket through python.
Hope this helps!
Adam.
Is there an updated version of this video for Alpaca? Trying wscat with the provided wss feeds is not working now. It looks to me like Alpaca is doing something else, as their docs indicate use of https: addresses for websocket feeds, but that doesn't work using wscat. Something is missing the mark here! Thanks for the help.
I encountered same problem. Are there any solution?
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?
Thanks, in more recent videos I do this, but only for crypto so far. Same concept though. I will do a version for stocks, I have quite a few videos to make in my queue, but will get to it.
@@parttimelarry Thank you! but the run_forever() method is blocking all of my code after it from being executed.. How do I fix this?
Can you demonstrate how to put the live quote on a text box where the content is refreshed each time new message is received ?
Do you mean on the web? Yeah I think it would be a cool tutorial to build a real time trading dashboard, so will put this on my list.
Hi Larry, this is awesome. Do you know how can I send the message to render.template html in Flask?
Thanks
Great job@Part Time Larry can you create the same one for SSE
hope you have refreshed your api key.. would blur some screens
I delete them after every video
Hello, first of all, tell you that your videos are very good and they have clarified me enough on the subject. Could you explain or point me to the video, if you have talked about the continuity of the data? It happens to me that I stop receiving on_message but the websocket is still connected, how do I resume the transmission?
On the other hand, the websocket also closes if there is an internet cut, isn't it supposed that run_forever () should automatically reconnect? I am working with webscoketApp and binance. From already thank you very much.
Is it neccessary to use Kafka here and Spark for real-time data processing if we wanted to to some data visualization and processing? Let's say we wanted to have 10 different currency pairs and then monitor them, or I misunderstood their purpose and they are not needed here?
But how can I actually use this data (not print it), but use in if/else statements?
if you can print it, it means that you have
as you can see in his terminal it's a list, do whatever you want with it :)
Hey Larry, I love your videos and had a specific question on this in particular. I am having the hardest time getting websocket data to run through a pandas dataframe. Any quick tips? (yes im an idiot)
Hey Larry how about some examples on python hyperthreading. Thanks!
Hi, thanks for the video, really helpful! is there a way to stream all tickers that are associated with alpaca instead of subscribing to specific stocks?
Every ticker might be a bit much I think, but maybe. There is an API method in the alpaca docs that returns all the available tickers. I suppose you could create sockets to listen on all of them, but haven't tried.
They currently limit to 30 channels per API key I believe.
Good. But if you want to get multiple stock data, then what to do
Can you do a buffer to acumulate for example 15 candles and crete indicators with this buffer like RSI, MACD etc?
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:\Users\Administrator\Desktop\Websocket>python app.py
opened
reaceived a message
[{"ev":"status","status":"connected","message":"Connected Successfully"}]
reaceived a message
[{"ev":"status","status":"auth_failed","message":"authentication failed"}]
Nice video. If one needs data for multiple stocks, do you need to create multiple websockets?
I believe you can do a comma separated list of tickers, will need to double check the docs.
@@parttimelarry can you show how to do that? please I will like to know that
Hi , can u make a video which can send and receive simultaneously without closing the socket ?
this is 3yrs old, what's the current best way to do this?
I typed the same thing as you but for some reason my on_open function is getting called. Do you have any ideas why?
I've been googling for the past hour and can't find shit
Hey, can you suggest a method to share the websocket data feed from a single subscription to multiple python trading scripts?
The broker that I am using is having a limitation of only 3 websocket connections at any given instant.
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..
I have an API endpoint that I want to setup a web socket for so i can stream the data live. any ideas?
Where would you get data from non-US exchanges, please?
Will this end up costing $200/month? should i consider quandl or just use my ibkr api to get price data instead?
If you put a few bucks in an Alpaca brokerage account, then you have a funded account with access to their market data.
Anyone still using this? Does this still work? Trying to avoid unnecessary effort. Thanks in Advance!
Hello sir,will you please add more functionalities to create Stock Price Alert system with this data....Thanks in advance...
That's a great idea. I just posted a newer streaming market data video, so I think alerting would be a perfect addition. Next video I will render a chart and implement alerting.
@@parttimelarry Thanks a lot sir....Appreciate your work..
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
What is I want to add TLS
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"}]
you did not show how to unsubscribe
brother ! i need your help plss..
hi larry, could you code me an app with streaming price distributed to multiple users at the same time, I will hire your services
Where can one download source code?
GitHub.com/financehacks
github.com/hackingthemarkets/alpaca-websockets
My paper account with a new authentication fails. Do I need some funding even on paper account? Thanks.
""
opened
received a message
[{"ev":"status","status":"connected","message":"Connected Successfully"}]
received a message
[{"ev":"status","status":"auth_failed","message":"authentication failed"}]
"
Does anybody know what is this line ws = websocket.WebSocketApp(SOCKET...) etc?
WebSocketApp is not defined in websocket!
Answering myself here: It is not defined in websocket but in websocket-client.