py_alpaca_api.trading.account ============================= .. py:module:: py_alpaca_api.trading.account Exceptions ---------- .. autoapisummary:: py_alpaca_api.trading.account.APIRequestError Classes ------- .. autoapisummary:: py_alpaca_api.trading.account.Requests py_alpaca_api.trading.account.AccountActivityModel py_alpaca_api.trading.account.AccountConfigModel py_alpaca_api.trading.account.AccountModel py_alpaca_api.trading.account.Account Functions --------- .. autoapisummary:: py_alpaca_api.trading.account.account_activity_class_from_dict py_alpaca_api.trading.account.account_config_class_from_dict py_alpaca_api.trading.account.account_class_from_dict Module Contents --------------- .. py:exception:: APIRequestError(status_code: int | None = None, message: str = '') Bases: :py:obj:`PyAlpacaAPIError` Raised when an API request fails. .. py:class:: Requests .. py:method:: 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) Execute HTTP request with retry logic. :param method: A string representing the HTTP method to be used in the request. :param url: A string representing the URL to send the request to. :param headers: An optional dictionary containing the headers for the request. :param params: An optional dictionary containing the query parameters for the request. :param json: An optional dictionary containing the JSON payload for the request. :param 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:class:: AccountActivityModel .. py:attribute:: activity_type :type: str .. py:attribute:: id :type: str .. py:attribute:: cum_qty :type: float .. py:attribute:: leaves_qty :type: float .. py:attribute:: price :type: float .. py:attribute:: qty :type: float .. py:attribute:: side :type: str .. py:attribute:: symbol :type: str .. py:attribute:: transaction_time :type: datetime.datetime .. py:attribute:: order_id :type: str .. py:attribute:: type :type: str .. py:attribute:: order_status :type: str .. py:attribute:: date :type: datetime.datetime .. py:attribute:: net_amount :type: float .. py:attribute:: per_share_amount :type: float .. py:function:: account_activity_class_from_dict(data_dict: dict) -> AccountActivityModel Converts a dictionary into an instance of the `AccountActivityModel`. :param data_dict: A dictionary containing the data for creating an instance of AccountActivityModel. :returns: An instance of the AccountActivityModel class. :raises None: .. py:class:: AccountConfigModel Model for account configuration settings. .. attribute:: dtbp_check Day trade buying power check setting ("entry", "exit", "both") .. attribute:: fractional_trading Whether fractional trading is enabled .. attribute:: max_margin_multiplier Maximum margin multiplier allowed ("1", "2", "4") .. attribute:: no_shorting Whether short selling is disabled .. attribute:: pdt_check Pattern day trader check setting ("entry", "exit", "both") .. attribute:: ptp_no_exception_entry Whether PTP no exception entry is enabled .. attribute:: suspend_trade Whether trading is suspended .. attribute:: trade_confirm_email Trade confirmation email setting ("all", "none") .. py:attribute:: dtbp_check :type: str .. py:attribute:: fractional_trading :type: bool .. py:attribute:: max_margin_multiplier :type: str .. py:attribute:: no_shorting :type: bool .. py:attribute:: pdt_check :type: str .. py:attribute:: ptp_no_exception_entry :type: bool .. py:attribute:: suspend_trade :type: bool .. py:attribute:: trade_confirm_email :type: str .. py:function:: account_config_class_from_dict(data: dict) -> AccountConfigModel Create AccountConfigModel from API response dictionary. :param data: Dictionary containing account configuration data from API :returns: AccountConfigModel instance .. py:class:: AccountModel .. py:attribute:: id :type: str .. py:attribute:: account_number :type: str .. py:attribute:: status :type: str .. py:attribute:: crypto_status :type: str .. py:attribute:: options_approved_level :type: int .. py:attribute:: options_trading_level :type: int .. py:attribute:: currency :type: str .. py:attribute:: buying_power :type: float .. py:attribute:: regt_buying_power :type: float .. py:attribute:: daytrading_buying_power :type: float .. py:attribute:: effective_buying_power :type: float .. py:attribute:: non_marginable_buying_power :type: float .. py:attribute:: options_buying_power :type: float .. py:attribute:: bod_dtbp :type: float .. py:attribute:: cash :type: float .. py:attribute:: accrued_fees :type: float .. py:attribute:: pending_transfer_in :type: float .. py:attribute:: portfolio_value :type: float .. py:attribute:: pattern_day_trader :type: bool .. py:attribute:: trading_blocked :type: bool .. py:attribute:: transfers_blocked :type: bool .. py:attribute:: account_blocked :type: bool .. py:attribute:: created_at :type: datetime.datetime .. py:attribute:: trade_suspended_by_user :type: bool .. py:attribute:: multiplier :type: int .. py:attribute:: shorting_enabled :type: bool .. py:attribute:: equity :type: float .. py:attribute:: last_equity :type: float .. py:attribute:: long_market_value :type: float .. py:attribute:: short_market_value :type: float .. py:attribute:: position_market_value :type: float .. py:attribute:: initial_margin :type: float .. py:attribute:: maintenance_margin :type: float .. py:attribute:: last_maintenance_margin :type: float .. py:attribute:: sma :type: float .. py:attribute:: daytrade_count :type: int .. py:attribute:: balance_asof :type: str .. py:attribute:: crypto_tier :type: int .. py:attribute:: intraday_adjustments :type: int .. py:attribute:: pending_reg_taf_fees :type: float .. py:function:: account_class_from_dict(data_dict: dict) -> AccountModel Converts a dictionary into an instance of the `AccountModel`. :param data_dict: A dictionary containing the data for the `AccountModel` instance. :type data_dict: dict :returns: An instance of the `AccountModel` created from the provided dictionary. :rtype: AccountModel .. py:class:: Account(headers: dict[str, str], base_url: str) .. py:method:: get() -> py_alpaca_api.models.account_model.AccountModel Retrieves the user's account information. :returns: The user's account model. :rtype: AccountModel .. py:method:: activities(activity_type: str, date: str | None = None, until_date: str | None = None) -> list[py_alpaca_api.models.account_activity_model.AccountActivityModel] Retrieves the account activities for the specified activity type. Optionally filtered by date or until date. :param activity_type: The type of account activity to retrieve. :type activity_type: str :param date: The date to filter the activities by. If provided, only activities on this date will be returned. :type date: str, optional :param until_date: The date to filter the activities up to. If provided, only activities up to and including this date will be returned. :type until_date: str, optional :returns: A list of account activity models representing the retrieved activities. :rtype: List[AccountActivityModel] :raises ValueError: If the activity type is not provided, or if both date and until_date are provided. .. py:method:: portfolio_history(period: str = '1W', timeframe: str = '1D', intraday_reporting: str = 'market_hours') -> pandas.DataFrame Retrieves portfolio history data. :param period: The period of time for which the portfolio history is requested. Defaults to "1W" (1 week). :type period: str :param timeframe: The timeframe for the intervals of the portfolio history. Defaults to "1D" (1 day). :type timeframe: str :param intraday_reporting: The type of intraday reporting to be used. Defaults to "market_hours". :type intraday_reporting: str :returns: A pandas DataFrame containing the portfolio history data. :rtype: pd.DataFrame :raises Exception: If the request to the Alpaca API fails. .. py:method:: get_configuration() -> py_alpaca_api.models.account_config_model.AccountConfigModel Retrieves the current account configuration settings. :returns: The current account configuration. :rtype: AccountConfigModel :raises APIRequestError: If the request to retrieve configuration fails. .. py:method:: 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 Updates the account configuration settings. :param dtbp_check: Day trade buying power check ("entry", "exit", "both") :param fractional_trading: Whether to enable fractional trading :param max_margin_multiplier: Maximum margin multiplier ("1", "2", "4") :param no_shorting: Whether to disable short selling :param pdt_check: Pattern day trader check ("entry", "exit", "both") :param ptp_no_exception_entry: Whether to enable PTP no exception entry :param suspend_trade: Whether to suspend trading :param trade_confirm_email: Trade confirmation emails ("all", "none") :returns: The updated account configuration. :rtype: AccountConfigModel :raises APIRequestError: If the request to update configuration fails. :raises ValueError: If invalid parameter values are provided.