py_alpaca_api.stock.snapshots
Exceptions
Raised when an API request fails. |
|
Raised when input validation fails. |
Classes
Functions
|
Module Contents
- exception py_alpaca_api.stock.snapshots.APIRequestError(status_code: int | None = None, message: str = '')[source]
Bases:
PyAlpacaAPIErrorRaised when an API request fails.
- exception py_alpaca_api.stock.snapshots.ValidationError[source]
Bases:
PyAlpacaAPIErrorRaised when input validation fails.
- class py_alpaca_api.stock.snapshots.Requests[source]
- request(method: str, url: str, headers: dict[str, str] | None = None, params: dict[str, str | bool | float | int] | None = None, json: dict[str, Any] | None = None, raw_response: bool = False)[source]
Execute HTTP request with retry logic.
- Parameters:
method – A string representing the HTTP method to be used in the request.
url – A string representing the URL to send the request to.
headers – An optional dictionary containing the headers for the request.
params – An optional dictionary containing the query parameters for the request.
json – An optional dictionary containing the JSON payload for the request.
raw_response – If True, return the raw response object without status checks. Defaults to False.
- Returns:
The response object returned by the server.
- Raises:
APIRequestError – If the response status code is not one of the acceptable statuses (200, 204, 207) and raw_response is False.
- class py_alpaca_api.stock.snapshots.SnapshotModel[source]
-
- latest_trade: py_alpaca_api.models.trade_model.TradeModel | None = None
- latest_quote: py_alpaca_api.models.quote_model.QuoteModel | None = None
- py_alpaca_api.stock.snapshots.snapshot_class_from_dict(data: dict) SnapshotModel[source]
- class py_alpaca_api.stock.snapshots.Snapshots(headers: dict[str, str])[source]
- get_snapshot(symbol: str, feed: str = 'iex') py_alpaca_api.models.snapshot_model.SnapshotModel[source]
Get a snapshot of a single stock symbol.
The snapshot includes the latest trade, latest quote, minute bar, daily bar, and previous daily bar data.
- Parameters:
symbol – The stock symbol to get snapshot for.
feed – The data feed to use (“iex”, “sip”, or “otc”). Defaults to “iex”.
- Returns:
A SnapshotModel containing the snapshot data.
- Raises:
ValidationError – If symbol is invalid or feed is invalid.
APIRequestError – If the API request fails.
- get_snapshots(symbols: list[str] | str, feed: str = 'iex') list[py_alpaca_api.models.snapshot_model.SnapshotModel] | dict[str, py_alpaca_api.models.snapshot_model.SnapshotModel][source]
Get snapshots for multiple stock symbols.
The snapshot includes the latest trade, latest quote, minute bar, daily bar, and previous daily bar data for each symbol.
- Parameters:
symbols – A list of stock symbols or comma-separated string of symbols.
feed – The data feed to use (“iex”, “sip”, or “otc”). Defaults to “iex”.
- Returns:
A dictionary mapping symbols to their SnapshotModel objects, or a list of SnapshotModel objects if only one symbol is provided.
- Raises:
ValidationError – If symbols are invalid or feed is invalid.
APIRequestError – If the API request fails.