py_alpaca_api.stock.assets
Exceptions
Raised when an API request fails. |
Classes
Functions
|
Create AssetModel from dictionary data. |
Module Contents
- exception py_alpaca_api.stock.assets.APIRequestError(status_code: int | None = None, message: str = '')[source]
Bases:
PyAlpacaAPIErrorRaised when an API request fails.
- class py_alpaca_api.stock.assets.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.
- py_alpaca_api.stock.assets.asset_class_from_dict(data_dict: dict) AssetModel[source]
Create AssetModel from dictionary data.
- Parameters:
data_dict – A dictionary containing the data for creating an instance of AssetModel.
- Returns:
An instance of the AssetModel class.
- Raises:
None –
- class py_alpaca_api.stock.assets.Assets(base_url: str, headers: dict[str, str])[source]
- get(symbol: str) py_alpaca_api.models.asset_model.AssetModel[source]
Retrieves an AssetModel for the specified symbol.
- get_all(status: str = 'active', exchange: str = '', excluded_exchanges: list[str] | None = None) pandas.DataFrame[source]
Retrieves a DataFrame of all active, fractionable, and tradable assets.
Excluding those from the OTC exchange.
- Parameters:
status (str, optional) – The status of the assets to retrieve. Defaults to “active”.
exchange (str, optional) – The exchange to filter the assets by. Defaults to an empty string, which retrieves assets from all exchanges.
excluded_exchanges (List[str], optional) – A list of exchanges to exclude from the results. Defaults to [“OTC”].
- Returns:
A DataFrame containing the retrieved assets.
- Return type:
pd.DataFrame