py_alpaca_api.stock.assets

Exceptions

APIRequestError

Raised when an API request fails.

Classes

Requests

AssetModel

Assets

Functions

asset_class_from_dict(→ AssetModel)

Create AssetModel from dictionary data.

Module Contents

exception py_alpaca_api.stock.assets.APIRequestError(status_code: int | None = None, message: str = '')[source]

Bases: PyAlpacaAPIError

Raised 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.

class py_alpaca_api.stock.assets.AssetModel[source]
id: str
asset_class: str
easy_to_borrow: bool
exchange: str
fractionable: bool
maintenance_margin_requirement: float
marginable: bool
name: str
shortable: bool
status: str
symbol: str
tradable: bool
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.

Parameters:

symbol (str) – The symbol of the asset to retrieve.

Returns:

The AssetModel for the specified asset.

Return type:

AssetModel

Raises:

Exception – If the asset is not a US Equity (stock).

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