py_alpaca_api.trading.account
Exceptions
Raised when an API request fails. |
Classes
Model for account configuration settings. |
|
Functions
|
Converts a dictionary into an instance of the AccountActivityModel. |
|
Create AccountConfigModel from API response dictionary. |
|
Converts a dictionary into an instance of the AccountModel. |
Module Contents
- exception py_alpaca_api.trading.account.APIRequestError(status_code: int | None = None, message: str = '')[source]
Bases:
PyAlpacaAPIErrorRaised when an API request fails.
- class py_alpaca_api.trading.account.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.trading.account.AccountActivityModel[source]
-
- transaction_time: datetime.datetime
- date: datetime.datetime
- py_alpaca_api.trading.account.account_activity_class_from_dict(data_dict: dict) AccountActivityModel[source]
Converts a dictionary into an instance of the AccountActivityModel.
- Parameters:
data_dict – A dictionary containing the data for creating an instance of AccountActivityModel.
- Returns:
An instance of the AccountActivityModel class.
- Raises:
None –
- class py_alpaca_api.trading.account.AccountConfigModel[source]
Model for account configuration settings.
- dtbp_check
Day trade buying power check setting (“entry”, “exit”, “both”)
- fractional_trading
Whether fractional trading is enabled
- max_margin_multiplier
Maximum margin multiplier allowed (“1”, “2”, “4”)
- no_shorting
Whether short selling is disabled
- pdt_check
Pattern day trader check setting (“entry”, “exit”, “both”)
- ptp_no_exception_entry
Whether PTP no exception entry is enabled
- suspend_trade
Whether trading is suspended
- trade_confirm_email
Trade confirmation email setting (“all”, “none”)
- py_alpaca_api.trading.account.account_config_class_from_dict(data: dict) AccountConfigModel[source]
Create AccountConfigModel from API response dictionary.
- Parameters:
data – Dictionary containing account configuration data from API
- Returns:
AccountConfigModel instance
- class py_alpaca_api.trading.account.AccountModel[source]
-
- created_at: datetime.datetime
- py_alpaca_api.trading.account.account_class_from_dict(data_dict: dict) AccountModel[source]
Converts a dictionary into an instance of the AccountModel.
- Parameters:
data_dict (dict) – A dictionary containing the data for the AccountModel instance.
- Returns:
An instance of the AccountModel created from the provided dictionary.
- Return type:
- class py_alpaca_api.trading.account.Account(headers: dict[str, str], base_url: str)[source]
- get() py_alpaca_api.models.account_model.AccountModel[source]
Retrieves the user’s account information.
- Returns:
The user’s account model.
- Return type:
- activities(activity_type: str, date: str | None = None, until_date: str | None = None) list[py_alpaca_api.models.account_activity_model.AccountActivityModel][source]
Retrieves the account activities for the specified activity type.
Optionally filtered by date or until date.
- Parameters:
activity_type (str) – The type of account activity to retrieve.
date (str, optional) – The date to filter the activities by. If provided, only activities on this date will be returned.
until_date (str, optional) – The date to filter the activities up to. If provided, only activities up to and including this date will be returned.
- Returns:
- A list of account activity models
representing the retrieved activities.
- Return type:
List[AccountActivityModel]
- Raises:
ValueError – If the activity type is not provided, or if both date and until_date are provided.
- portfolio_history(period: str = '1W', timeframe: str = '1D', intraday_reporting: str = 'market_hours') pandas.DataFrame[source]
Retrieves portfolio history data.
- Parameters:
period (str) – The period of time for which the portfolio history is requested. Defaults to “1W” (1 week).
timeframe (str) – The timeframe for the intervals of the portfolio history. Defaults to “1D” (1 day).
intraday_reporting (str) – The type of intraday reporting to be used. Defaults to “market_hours”.
- Returns:
A pandas DataFrame containing the portfolio history data.
- Return type:
pd.DataFrame
- Raises:
Exception – If the request to the Alpaca API fails.
- get_configuration() py_alpaca_api.models.account_config_model.AccountConfigModel[source]
Retrieves the current account configuration settings.
- Returns:
The current account configuration.
- Return type:
- Raises:
APIRequestError – If the request to retrieve configuration fails.
- update_configuration(dtbp_check: str | None = None, fractional_trading: bool | None = None, max_margin_multiplier: str | None = None, no_shorting: bool | None = None, pdt_check: str | None = None, ptp_no_exception_entry: bool | None = None, suspend_trade: bool | None = None, trade_confirm_email: str | None = None) py_alpaca_api.models.account_config_model.AccountConfigModel[source]
Updates the account configuration settings.
- Parameters:
dtbp_check – Day trade buying power check (“entry”, “exit”, “both”)
fractional_trading – Whether to enable fractional trading
max_margin_multiplier – Maximum margin multiplier (“1”, “2”, “4”)
no_shorting – Whether to disable short selling
pdt_check – Pattern day trader check (“entry”, “exit”, “both”)
ptp_no_exception_entry – Whether to enable PTP no exception entry
suspend_trade – Whether to suspend trading
trade_confirm_email – Trade confirmation emails (“all”, “none”)
- Returns:
The updated account configuration.
- Return type:
- Raises:
APIRequestError – If the request to update configuration fails.
ValueError – If invalid parameter values are provided.