-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Real-time News Data Stream via WebSocket Subscription (#392)
* Added News Stream * updated readme * Remove NEWS_DATA_STREAM * poetry pre-commit * update readme * test_cast * test_cast * test_cast * test_cast * test_cast * test_cast * clean up test_case.py imports * fixed news model issues * news websocket.py _dispatch fix * websocket raw_data=false testing * fixed timestamp to datetime in news ws * remove any * revert NewsClient namechange * Added TimeSeriesMixin to News model * set news.images default none * Update README.md Co-authored-by: hiohiohio <[email protected]> * resolved comments * remove test timestamp * instatiate handler per symbol * handler fix * duplicate calls * adjust code to merge * fix adjusted code --------- Co-authored-by: hiohiohio <[email protected]> Co-authored-by: Chihiro Hio <[email protected]>
- Loading branch information
1 parent
e092f3f
commit 7bdfe2f
Showing
7 changed files
with
197 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from typing import Optional, Dict | ||
|
||
from alpaca.common.enums import BaseURL | ||
from alpaca.common.websocket import BaseStream | ||
|
||
|
||
class NewsDataStream(BaseStream): | ||
""" | ||
A WebSocket client for streaming news. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
api_key: str, | ||
secret_key: str, | ||
raw_data: bool = False, | ||
websocket_params: Optional[Dict] = None, | ||
url_override: Optional[str] = None, | ||
) -> None: | ||
""" | ||
Instantiates a WebSocket client for accessing live news. | ||
Args: | ||
api_key (str): Alpaca API key. | ||
secret_key (str): Alpaca API secret key. | ||
raw_data (bool): Whether to return wrapped data or raw API data. Defaults to False. | ||
websocket_params (Optional[Dict], optional): Any parameters for configuring websocket | ||
connection. Defaults to None. | ||
url_override (Optional[str]): If specified allows you to override the base url the client | ||
points to for proxy/testing. Defaults to None. | ||
""" | ||
super().__init__( | ||
endpoint=( | ||
url_override | ||
if url_override is not None | ||
else BaseURL.MARKET_DATA_STREAM.value + "/v1beta1/news" | ||
), | ||
api_key=api_key, | ||
secret_key=secret_key, | ||
raw_data=raw_data, | ||
websocket_params=websocket_params, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.