Skip to content

Commit

Permalink
feat: support option stream data
Browse files Browse the repository at this point in the history
  • Loading branch information
hiohiohio committed Jan 24, 2024
1 parent 791ce40 commit 4dbfcd1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions alpaca/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BaseURL(str, Enum):
TRADING_LIVE = "https://api.alpaca.markets"
DATA = "https://data.alpaca.markets"
MARKET_DATA_STREAM = "wss://stream.data.alpaca.markets"
OPTION_DATA_STREAM = "wss://stream-options.data.alpaca.markets"
TRADING_STREAM_PAPER = "wss://paper-api.alpaca.markets/stream"
TRADING_STREAM_LIVE = "wss://api.alpaca.markets/stream"

Expand Down
44 changes: 44 additions & 0 deletions alpaca/data/live/option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Dict, Optional

from alpaca.common.enums import BaseURL
from alpaca.common.websocket import BaseStream
from alpaca.data.enums import DataFeed


class OptionDataStream(BaseStream):
"""
A WebSocket client for streaming live option data.
See BaseStream for more information on implementation and the methods available.
"""

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 option data.
Args:
api_key (str): Alpaca API key.
secret_key (str): Alpaca API secret key.
raw_data (bool, optional): 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.OPTION_DATA_STREAM.value + "/v1beta1/opra"
),
api_key=api_key,
secret_key=secret_key,
raw_data=raw_data,
websocket_params=websocket_params,
)

0 comments on commit 4dbfcd1

Please sign in to comment.