alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
537 stars 134 forks source link

Real-time News Data Stream via WebSocket Subscription #369

Closed IsaacTrevino closed 8 months ago

IsaacTrevino commented 10 months ago

Description

This pull request adds a powerful new feature to the Alpaca-py library: a real-time news data stream available via WebSocket subscription. This functionality lets users stay updated on market trends, relevant company news, and other events that could influence trading decisions.

Changes

Motivation

With the volatility of financial markets, staying informed is critical for casual traders and financial institutions. News can considerably impact trading decisions, making a real-time news data stream a valuable asset for any trading toolkit.

Usage Example

Here's a quick example to get you started with the new feature. This demonstrates how to subscribe to the news feed for a specific stock symbol:

from alpaca.data.live.news import NewsDataStream

# Initialize news client stream
news_client = NewsDataStream('api-key', 'secret-key')

# Subscribe to the news data stream
async def news_callback(news):
    print(news)

    news_client.subscribe_news(news_callback, 'APPL')
    news_client.run()

Dependencies

Questions

  1. Should we expand this feature to include filters for news categories or sources?
  2. Would the integration of sentiment analysis for news articles be beneficial?

Your feedback is welcome. It's the apple to our pie! 🍎 🥧

Let's merge this and make the Alpaca-py library not just better but utterly unmissable. 🦙

hiohiohio commented 10 months ago

@IsaacTrevino overall LGTM! Can you please adjust minor lint thing?

IsaacTrevino commented 10 months ago

Linting check should work now 👍

IsaacTrevino commented 10 months ago

2. Do you mind adding a test case for msg_type = "n" in test_websockets.py/test_cast to test the changes you've made in the _dispatch method?

@alessiocastrica , Okay I was able to remove those changes my linter did automatically for README.md. Also I added the test_cast as well as the _cast method in websockets.py. Being new to testing please let me know if I did this correct in my latest commit.

IsaacTrevino commented 10 months ago

@alessiocastrica Alright, I was able to add the News test case. Please look and let me know if you have any questions. I am excited to contribute to this repo as I plan to utilize it in my projects.

Edit: It looks like News model requires more work. I am investigating the cause now.

IsaacTrevino commented 10 months ago

FYI ready for review

hiohiohio commented 10 months ago

Sorry for taking time to review. Please let me have a time sometime sooner.

IsaacTrevino commented 10 months ago

Sorry for taking time to review. Please let me have a time sometime sooner.

No problem, I was able to commit your suggestion.