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...

Комментарии • 88

  • @ErolAspromatis
    @ErolAspromatis 4 года назад +23

    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.

  • @jeroenvermunt3372
    @jeroenvermunt3372 3 года назад

    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.

  • @mschuer100
    @mschuer100 4 года назад +3

    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.

  • @NicciXRP
    @NicciXRP 8 месяцев назад

    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❤️👊🏼

    • @parttimelarry
      @parttimelarry  8 месяцев назад

      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.

  • @thirdreplicator
    @thirdreplicator 3 года назад +1

    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.

    • @parttimelarry
      @parttimelarry  3 года назад

      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.

  • @semeradstephan
    @semeradstephan 4 года назад +1

    Awesome Video! I am amazed that at this point you only have 6K Views

  • @michaelswiercz3357
    @michaelswiercz3357 4 года назад +1

    Great video! Simple and to the point in less than 15 minutes.

  • @Jatin19902
    @Jatin19902 3 года назад +1

    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.

  • @US100
    @US100 4 года назад +2

    Awesome Tutorial this Series will be very nice

  • @Clockwise.00
    @Clockwise.00 4 года назад +2

    Super interesting content, waiting for next.

  • @rakeshrakesh0729
    @rakeshrakesh0729 4 года назад +2

    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.

  • @jasonbourne5825
    @jasonbourne5825 2 года назад

    Your lecture helps me a lot, thank you.

  • @michaelbdd
    @michaelbdd 3 года назад +1

    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?

  • @vicvol7360
    @vicvol7360 Год назад +1

    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

  • @PyMoondra
    @PyMoondra 3 года назад

    Great channel. Been trading recently, and trying to build some Python apps to find setups.

  • @utkarshs060
    @utkarshs060 3 года назад +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.

    • @ricomajestic
      @ricomajestic Год назад

      Yea would love to see that too. How to write real time data to a database.

  • @davidsilverberg8327
    @davidsilverberg8327 2 года назад

    Thanks so much for this video man

  • @arpitvijayvargiya1371
    @arpitvijayvargiya1371 2 года назад

    Thank you this.

  • @akramdahmani7214
    @akramdahmani7214 3 года назад

    Great tutorial, thanks 👍

  • @danielnelson9996
    @danielnelson9996 4 года назад +2

    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

  • @LucaSpinello
    @LucaSpinello 3 года назад

    Great video thank you! Can you do another one on how to handle websocket with a sync please

  • @ibn-nafis3434
    @ibn-nafis3434 4 года назад +1

    Thanks Boss

  • @CarlosRomeroconnect
    @CarlosRomeroconnect 4 года назад +1

    Amazing!

  • @hsan0184
    @hsan0184 3 года назад

    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)?

  • @peterluro8649
    @peterluro8649 3 месяца назад

    Great video! what is the most accurate realtime stock data library for Python? (Ideally with the best price)

  • @suleimana678
    @suleimana678 9 месяцев назад

    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?

  • @nicholasrotich4295
    @nicholasrotich4295 4 года назад +2

    thank you for your wonderful tutorials. Any chance that the connection fails if you are using paper account?

    • @parttimelarry
      @parttimelarry  4 года назад

      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.

    • @vivaTahrir
      @vivaTahrir 4 года назад +3

      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.

  • @tbjasun
    @tbjasun 3 года назад +1

    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.

  • @AlexJaeger716
    @AlexJaeger716 4 года назад +2

    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?

    • @parttimelarry
      @parttimelarry  4 года назад +1

      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.

    • @AlexJaeger716
      @AlexJaeger716 4 года назад

      @@parttimelarry Thank you! but the run_forever() method is blocking all of my code after it from being executed.. How do I fix this?

  • @ABGTronic_Inc
    @ABGTronic_Inc 4 года назад +1

    Can you demonstrate how to put the live quote on a text box where the content is refreshed each time new message is received ?

    • @parttimelarry
      @parttimelarry  4 года назад +1

      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.

  • @MrBraianzzz
    @MrBraianzzz 3 года назад +1

    Hi Larry, this is awesome. Do you know how can I send the message to render.template html in Flask?
    Thanks

  • @sanjeethnt5653
    @sanjeethnt5653 3 года назад

    Great job@Part Time Larry can you create the same one for SSE

  • @nikschuetz4112
    @nikschuetz4112 2 года назад

    hope you have refreshed your api key.. would blur some screens

  • @livedev
    @livedev 3 года назад

    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.

  • @bullet4255
    @bullet4255 Год назад

    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?

  • @michaelscarn7375
    @michaelscarn7375 4 года назад +1

    But how can I actually use this data (not print it), but use in if/else statements?

    • @akramdahmani7214
      @akramdahmani7214 3 года назад

      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 :)

  • @fearvalue1441
    @fearvalue1441 Год назад

    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)

  • @alerto2451
    @alerto2451 3 года назад

    Hey Larry how about some examples on python hyperthreading. Thanks!

  • @andrewenglish1418
    @andrewenglish1418 4 года назад +1

    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?

    • @parttimelarry
      @parttimelarry  4 года назад +1

      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.

    • @YannickvDijk
      @YannickvDijk 4 года назад

      They currently limit to 30 channels per API key I believe.

  • @guguladitya
    @guguladitya Год назад

    Good. But if you want to get multiple stock data, then what to do

  • @neurondeep
    @neurondeep 3 года назад

    Can you do a buffer to acumulate for example 15 candles and crete indicators with this buffer like RSI, MACD etc?

  • @vaibhavchogle2341
    @vaibhavchogle2341 4 года назад

    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"}]

  • @kalyanstock8058
    @kalyanstock8058 4 года назад

    Nice video. If one needs data for multiple stocks, do you need to create multiple websockets?

    • @parttimelarry
      @parttimelarry  4 года назад

      I believe you can do a comma separated list of tickers, will need to double check the docs.

    • @releveitcandol1995
      @releveitcandol1995 3 года назад

      @@parttimelarry can you show how to do that? please I will like to know that

  • @surajkhanra3767
    @surajkhanra3767 4 года назад

    Hi , can u make a video which can send and receive simultaneously without closing the socket ?

  • @ywueeee
    @ywueeee Год назад

    this is 3yrs old, what's the current best way to do this?

  • @jacobdietz4545
    @jacobdietz4545 Год назад

    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

  • @amanchaure5584
    @amanchaure5584 Год назад

    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.

  • @AlexJaeger716
    @AlexJaeger716 3 года назад

    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..

  • @lykiamusic
    @lykiamusic Год назад

    I have an API endpoint that I want to setup a web socket for so i can stream the data live. any ideas?

  • @Lorant1984
    @Lorant1984 2 года назад

    Where would you get data from non-US exchanges, please?

  • @mantisliving
    @mantisliving 4 года назад

    Will this end up costing $200/month? should i consider quandl or just use my ibkr api to get price data instead?

    • @kaleign
      @kaleign 4 года назад

      If you put a few bucks in an Alpaca brokerage account, then you have a funded account with access to their market data.

  • @nickmotor650
    @nickmotor650 6 месяцев назад

    Anyone still using this? Does this still work? Trying to avoid unnecessary effort. Thanks in Advance!

  • @swapnilpatil2445
    @swapnilpatil2445 4 года назад

    Hello sir,will you please add more functionalities to create Stock Price Alert system with this data....Thanks in advance...

    • @parttimelarry
      @parttimelarry  4 года назад +1

      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.

    • @swapnilpatil2445
      @swapnilpatil2445 4 года назад

      @@parttimelarry Thanks a lot sir....Appreciate your work..

  • @margeausoboti8864
    @margeausoboti8864 3 года назад

    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

  • @cunninghamb505
    @cunninghamb505 4 года назад

    What is I want to add TLS

  • @guillaumejames4222
    @guillaumejames4222 4 года назад +1

    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"}]

  • @rfyorfyo5022
    @rfyorfyo5022 2 года назад

    you did not show how to unsubscribe

  • @wtf9693
    @wtf9693 Год назад

    brother ! i need your help plss..

  • @abhay1302
    @abhay1302 3 года назад

    hi larry, could you code me an app with streaming price distributed to multiple users at the same time, I will hire your services

  • @icakinser
    @icakinser 4 года назад

    Where can one download source code?

  • @k2icc
    @k2icc 2 года назад

    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"}]
    "

  • @sergioametheone1
    @sergioametheone1 Год назад

    Does anybody know what is this line ws = websocket.WebSocketApp(SOCKET...) etc?
    WebSocketApp is not defined in websocket!

    • @sergioametheone1
      @sergioametheone1 Год назад

      Answering myself here: It is not defined in websocket but in websocket-client.