trade_clients ============= .. py:module:: trade_clients Classes ------- .. autoapisummary:: trade_clients.TradeAccount trade_clients.TradingClient trade_clients.LocalTradingClient trade_clients.RemoteTradingClient trade_clients.AlpacaClient Functions --------- .. autoapisummary:: trade_clients._json_default Module Contents --------------- .. py:class:: TradeAccount(/, **data) Bases: :py:obj:`alpaca.trading.models.TradeAccount` Represents trading account information for an Account. .. attribute:: id The account ID :type: UUID .. attribute:: account_number The account number :type: str .. attribute:: status The current status of the account :type: AccountStatus .. attribute:: crypto_status The status of the account in regards to trading crypto. Only present if crypto trading is enabled for your brokerage account. :type: Optional[AccountStatus] .. attribute:: currency Currently will always be the value "USD". :type: Optional[str] .. attribute:: buying_power Current available cash buying power. If multiplier = 2 then buying_power = max(equity-initial_margin(0) * 2). If multiplier = 1 then buying_power = cash. :type: Optional[str] .. attribute:: regt_buying_power User’s buying power under Regulation T (excess equity - (equity - margin value) - * margin multiplier) :type: Optional[str] .. attribute:: daytrading_buying_power The buying power for day trades for the account :type: Optional[str] .. attribute:: non_marginable_buying_power The non marginable buying power for the account :type: Optional[str] .. attribute:: cash Cash balance in the account :type: Optional[str] .. attribute:: accrued_fees Fees accrued in this account :type: Optional[str] .. attribute:: pending_transfer_out Cash pending transfer out of this account :type: Optional[str] .. attribute:: pending_transfer_in Cash pending transfer into this account :type: Optional[str] .. attribute:: portfolio_value Total value of cash + holding positions. (This field is deprecated. It is equivalent to the equity field.) :type: str .. attribute:: pattern_day_trader Whether the account is flagged as pattern day trader or not. :type: Optional[bool] .. attribute:: trading_blocked If true, the account is not allowed to place orders. :type: Optional[bool] .. attribute:: transfers_blocked If true, the account is not allowed to request money transfers. :type: Optional[bool] .. attribute:: account_blocked If true, the account activity by user is prohibited. :type: Optional[bool] .. attribute:: created_at Timestamp this account was created at :type: Optional[datetime] .. attribute:: trade_suspended_by_user If true, the account is not allowed to place orders. :type: Optional[bool] .. attribute:: multiplier Multiplier value for this account. :type: Optional[str] .. attribute:: shorting_enabled Flag to denote whether or not the account is permitted to short :type: Optional[bool] .. attribute:: equity This value is cash + long_market_value + short_market_value. This value isn't calculated in the SDK it is computed on the server and we return the raw value here. :type: Optional[str] .. attribute:: last_equity Equity as of previous trading day at 16:00:00 ET :type: Optional[str] .. attribute:: long_market_value Real-time MtM value of all long positions held in the account :type: Optional[str] .. attribute:: short_market_value Real-time MtM value of all short positions held in the account :type: Optional[str] .. attribute:: initial_margin Reg T initial margin requirement :type: Optional[str] .. attribute:: maintenance_margin Maintenance margin requirement :type: Optional[str] .. attribute:: last_maintenance_margin Maintenance margin requirement on the previous trading day :type: Optional[str] .. attribute:: sma Value of Special Memorandum Account (will be used at a later date to provide additional buying_power) :type: Optional[str] .. attribute:: daytrade_count The current number of daytrades that have been made in the last 5 trading days (inclusive of today) :type: Optional[int] .. attribute:: options_buying_power Your buying power for options trading :type: Optional[str] .. attribute:: options_approved_level The options trading level that was approved for this account. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put, 3=Spreads/Straddles. :type: Optional[int] .. attribute:: options_trading_level The effective options trading level of the account. This is the minimum between account options_approved_level and account configurations max_options_trading_level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long, 3=Spreads/Straddles. :type: Optional[int] .. py:attribute:: initial_cash :type: float | None :value: None .. py:function:: _json_default(obj) JSON serializer for objects not serializable by default json code. .. py:class:: TradingClient(live, config, alpaca_account_client) Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: from_config(config, alpaca_account_client, live = False) :classmethod: .. py:attribute:: live .. py:attribute:: config :type: trading.cli.trading.trade_config.RRTradeConfig .. py:attribute:: alpaca_account_client .. py:attribute:: defer_trade_execution .. py:attribute:: _account .. py:method:: close(closed_positions, open_positions, pf_history, cash) .. py:method:: get_clock() .. py:method:: get_calendar() .. py:property:: account :type: TradeAccount .. py:property:: positions :type: dict[str, collections.deque[trading.src.portfolio.position.Position]] .. py:method:: _load_positions() :abstractmethod: .. py:method:: _load_account() :abstractmethod: .. py:method:: _load_pf_stats() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:method:: _load_closed_positions() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:method:: _write_open_positions(open_positions) .. py:method:: _write_account(cash) .. py:method:: _write_pf_stats(stats) .. py:method:: _write_closed_positions(closed_positions) .. py:method:: write_meta_data(meta_data) .. py:method:: execute_trades(actions) .. py:class:: LocalTradingClient(config, alpaca_account_client, live) Bases: :py:obj:`TradingClient` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: positions_path .. py:attribute:: account_path .. py:attribute:: closed_positions_path .. py:attribute:: account_value_series_path .. py:attribute:: meta_data_path .. py:method:: _resolve_path(path_field, default_name) :staticmethod: .. py:method:: write_meta_data(meta_data) .. py:method:: _write_open_positions(open_positions) .. py:method:: _write_account(cash) .. py:method:: _write_pf_stats(stats) .. py:method:: _write_closed_positions(closed_positions) .. py:method:: _load_positions() .. py:method:: _load_account() .. py:method:: _load_pf_stats() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:method:: _load_closed_positions() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:class:: RemoteTradingClient(config, alpaca_account_client, live) Bases: :py:obj:`TradingClient` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: _client .. py:attribute:: open_positions_key :value: '' .. py:attribute:: account_key :value: '' .. py:attribute:: closed_positions_key :value: '' .. py:attribute:: account_stats_key :value: '' .. py:attribute:: backtest_key :value: '' .. py:method:: _load_positions() .. py:method:: _load_account() .. py:method:: _load_pf_stats() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:method:: _load_closed_positions() This is not implemented for Alpaca cause the api manages these and it's just for historical tracking :param self: Description :return: Description :rtype: list[Position] .. py:method:: write_meta_data(meta_data) .. py:method:: _write_closed_positions(closed_positions) .. py:method:: _write_account(cash) .. py:method:: _write_open_positions(open_positions) .. py:method:: _write_pf_stats(stats) .. py:method:: write_backtest_results(backtest_dir) .. py:class:: AlpacaClient(config, alpaca_account_client = None, live = False) Bases: :py:obj:`TradingClient` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: _load_positions() .. py:method:: _load_account() .. py:method:: execute_trades(actions)