Historical Data#
StockHistoricalDataClient#
- class alpaca.data.historical.stock.StockHistoricalDataClient(api_key: Optional[str] = None, secret_key: Optional[str] = None, oauth_token: Optional[str] = None, use_basic_auth: bool = False, raw_data: bool = False, url_override: Optional[str] = None, sandbox: bool = False)#
The REST client for interacting with Alpaca Market Data API stock data endpoints.
Learn more on https://alpaca.markets/docs/market-data/
- __init__(api_key: Optional[str] = None, secret_key: Optional[str] = None, oauth_token: Optional[str] = None, use_basic_auth: bool = False, raw_data: bool = False, url_override: Optional[str] = None, sandbox: bool = False) None #
Instantiates a Historical Data Client.
- Parameters:
api_key (Optional[str], optional) – Alpaca API key. Defaults to None.
secret_key (Optional[str], optional) – Alpaca API secret key. Defaults to None.
oauth_token (Optional[str]) – The oauth token if authenticating via OAuth. Defaults to None.
use_basic_auth (bool, optional) – If true, API requests will use basic authorization headers. Set to true if using broker api sandbox credentials
raw_data (bool, optional) – If true, API responses will not be wrapped and raw responses will be returned from methods. Defaults to False. This has not been implemented yet.
url_override (Optional[str], optional) – If specified allows you to override the base url the client points to for proxy/testing.
sandbox (bool) – True if using sandbox mode. Defaults to False.
Get Stock Bars#
- StockHistoricalDataClient.get_stock_bars(request_params: StockBarsRequest) Union[BarSet, Dict[str, Any]] #
Returns bar data for an equity or list of equities over a given time period and timeframe.
- Parameters:
request_params (GetStockBarsRequest) – The request object for retrieving stock bar data.
- Returns:
The bar data either in raw or wrapped form
- Return type:
Union[BarSet, RawData]
Get Stock Quotes#
- StockHistoricalDataClient.get_stock_quotes(request_params: StockQuotesRequest) Union[QuoteSet, Dict[str, Any]] #
Returns level 1 quote data over a given time period for a security or list of securities.
- Parameters:
request_params (GetStockQuotesRequest) – The request object for retrieving stock quote data.
- Returns:
The quote data either in raw or wrapped form
- Return type:
Union[QuoteSet, RawData]
Get Stock Trades#
- StockHistoricalDataClient.get_stock_trades(request_params: StockTradesRequest) Union[TradeSet, Dict[str, Any]] #
Returns the price and sales history over a given time period for a security or list of securities.
- Parameters:
request_params (GetStockTradesRequest) – The request object for retrieving stock trade data.
- Returns:
The trade data either in raw or wrapped form
- Return type:
Union[TradeSet, RawData]
Get Stock Latest Quote#
- StockHistoricalDataClient.get_stock_latest_quote(request_params: StockLatestQuoteRequest) Union[Dict[str, Quote], Dict[str, Any]] #
Retrieves the latest quote for an equity symbol or list of equity symbols.
- Parameters:
request_params (StockLatestQuoteRequest) – The request object for retrieving the latest quote data.
- Returns:
The latest quote in raw or wrapped format
- Return type:
Union[Dict[str, Quote], RawData]
Get Stock Latest Trade#
- StockHistoricalDataClient.get_stock_latest_trade(request_params: StockLatestTradeRequest) Union[Dict[str, Trade], Dict[str, Any]] #
Retrieves the latest trade for an equity symbol or list of equities.
- Parameters:
request_params (StockLatestTradeRequest) – The request object for retrieving the latest trade data.
- Returns:
The latest trade in raw or wrapped format
- Return type:
Union[Dict[str, Trade], RawData]
Get Stock Latest Bar#
- StockHistoricalDataClient.get_stock_latest_bar(request_params: StockLatestBarRequest) Union[Dict[str, Bar], Dict[str, Any]] #
Retrieves the latest minute bar for an equity symbol or list of equity symbols.
- Parameters:
request_params (StockLatestBarRequest) – The request object for retrieving the latest bar data.
- Returns:
The latest minute bar in raw or wrapped format
- Return type:
Union[Dict[str, Bar], RawData]
Get Stock Snapshot#
- StockHistoricalDataClient.get_stock_snapshot(request_params: StockSnapshotRequest) Union[Dict[str, Snapshot], Dict[str, Any]] #
Returns snapshots of queried symbols. Snapshots contain latest trade, latest quote, latest minute bar, latest daily bar and previous daily bar data for the queried symbols.
- Parameters:
request_params (StockSnapshotRequest) – The request object for retrieving snapshot data.
- Returns:
The snapshot data either in raw or wrapped form
- Return type:
Union[SnapshotSet, RawData]