Base Broker Class

class algotradepy.brokers.base.ABroker(*args, simulation=True, **kwargs)

The Abstract Broker class defining the broker interface.

Parameters

simulation (bool, default True) – If set to True, the broker instance will be set to paper-trading mode. If a given broker implementation does not support paper-trading, it must raise NoPaperTradeException.

Notes

This class is deliberately kept minial until the optimal API is established and adopted by the other brokers.

abstract property acc_cash

The total funds available across all accounts.

abstract property datetime

Server date and time.

abstract property trades

Returns all trades placed in the current session.

abstract property open_trades

Returns all currently open trades placed in the ongoing session.

abstract sleep(secs)

Allows the server to deliver data.

abstract subscribe_to_new_trades(func, fn_kwargs=None)

Subscribe to being notified of all newly created orders.

The orders are transmitted only if they were successfully submitted.

Parameters
  • func (Callable) – The function to which to feed the bars. It must accept AContract and AnOrder as its sole positional arguments.

  • fn_kwargs (Dict) – Keyword arguments to feed to the callback function along with the bars.

abstract subscribe_to_trade_updates(func, fn_kwargs=None)

Subscribe to receiving updates on orders’ status.

Parameters
  • func (Callable) – The callback function. It must accept a Trade and a TradeStatus as its sole positional arguments.

  • fn_kwargs (dict) – The keyword arguments to pass to the callback function along with the positional arguments.

abstract subscribe_to_position_updates(func, fn_kwargs=None)

Subscribe to receiving position updates.

Parameters
  • func (Callable) – The callback function. It must accept a Position as its sole positional argument.

  • fn_kwargs (dict) – The keyword arguments to pass to the callback function along with the positional arguments.

abstract place_trade(trade, *args, **kwargs)

Place a trade with specified details.

Parameters

trade (Trade) – The trade to execute.

Returns

The tuple indicates if the order has been successfully placed, whereas the int is the associated order-id.

Return type

tuple of bool and int

abstract cancel_trade(trade)

Cancel placed traded.

Parameters

trade (Trade) – The trade to cancel.

abstract get_position(contract, *args, **kwargs)

Request the currently held position for a given symbol.

Parameters

contract (AContract) – The contract definition for which the position is required.

Returns

The current position for the specified symbol.

Return type

float

abstract get_transaction_fee()

Request the broker transaction cost.

Returns

The cost per transaction.

Return type

float