Skip to content

Commit

Permalink
fix: options data api method
Browse files Browse the repository at this point in the history
  • Loading branch information
hiohiohio committed Feb 5, 2024
1 parent f29ced4 commit 9cf433f
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 497 deletions.
105 changes: 53 additions & 52 deletions alpaca/data/historical/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,57 +72,58 @@ def __init__(
raw_data=raw_data,
)

def get_option_quotes(
self, request_params: OptionQuotesRequest
) -> Union[QuoteSet, RawData]:
"""Returns level 1 quote data over a given time period for a option or list of options.
Args:
request_params (GetOptionQuotesRequest): The request object for retrieving option quote data.
Returns:
Union[QuoteSet, RawData]: The quote data either in raw or wrapped form
"""
params = request_params.to_request_fields()

# paginated get request for market data api
raw_quotes = self._data_get(
endpoint_data_type="quotes",
endpoint_asset_class="options",
api_version=self._api_version,
**params,
)

if self._use_raw_data:
return raw_quotes

return QuoteSet(raw_quotes)

def get_option_trades(
self, request_params: OptionTradesRequest
) -> Union[TradeSet, RawData]:
"""Returns the price and sales history over a given time period for a option or list of options.
Args:
request_params (GetOptionTradesRequest): The request object for retrieving option trade data.
Returns:
Union[TradeSet, RawData]: The trade data either in raw or wrapped form
"""
params = request_params.to_request_fields()

# paginated get request for market data api
raw_trades = self._data_get(
endpoint_data_type="trades",
endpoint_asset_class="options",
api_version=self._api_version,
**params,
)

if self._use_raw_data:
return raw_trades

return TradeSet(raw_trades)
# not implemented yet
# def get_option_quotes(
# self, request_params: OptionQuotesRequest
# ) -> Union[QuoteSet, RawData]:
# """Returns level 1 quote data over a given time period for a option or list of options.

# Args:
# request_params (GetOptionQuotesRequest): The request object for retrieving option quote data.

# Returns:
# Union[QuoteSet, RawData]: The quote data either in raw or wrapped form
# """
# params = request_params.to_request_fields()

# # paginated get request for market data api
# raw_quotes = self._data_get(
# endpoint_data_type="quotes",
# endpoint_asset_class="options",
# api_version=self._api_version,
# **params,
# )

# if self._use_raw_data:
# return raw_quotes

# return QuoteSet(raw_quotes)

# def get_option_trades(
# self, request_params: OptionTradesRequest
# ) -> Union[TradeSet, RawData]:
# """Returns the price and sales history over a given time period for a option or list of options.

# Args:
# request_params (GetOptionTradesRequest): The request object for retrieving option trade data.

# Returns:
# Union[TradeSet, RawData]: The trade data either in raw or wrapped form
# """
# params = request_params.to_request_fields()

# # paginated get request for market data api
# raw_trades = self._data_get(
# endpoint_data_type="trades",
# endpoint_asset_class="options",
# api_version=self._api_version,
# **params,
# )

# if self._use_raw_data:
# return raw_trades

# return TradeSet(raw_trades)

def get_option_latest_quote(
self, request_params: OptionLatestQuoteRequest
Expand Down Expand Up @@ -153,7 +154,7 @@ def get_option_latest_quote(
def get_option_latest_trade(
self, request_params: OptionLatestTradeRequest
) -> Union[Dict[str, Trade], RawData]:
"""Retrieves the latest quote for an option symbol or list of option symbols.
"""Retrieves the latest trade for an option symbol or list of option symbols.
Args:
request_params (OptionLatestQuoteRequest): The request object for retrieving the latest quote data.
Expand Down
2 changes: 1 addition & 1 deletion alpaca/data/models/trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Trade(BaseModel):
exchange: Optional[Union[Exchange, str]] = None
price: float
size: float
id: Optional[int]
id: Optional[int] = None
conditions: Optional[Union[List[str], str]] = None
tape: Optional[str] = None

Expand Down
Loading

0 comments on commit 9cf433f

Please sign in to comment.