Simulation Broker Class¶
-
class
algotradepy.brokers.sim_broker.SimulationBroker(sim_streamer, starting_funds, transaction_cost=0, starting_positions=None)¶ Implements the broker interface for simulated back-testing.
The simulation broker uses the
SimulationDataStreamerto provide simulated brokerage functionality allowing to back-test trading algorithms before taking them to a live-trading environment.- Parameters
sim_streamer (SimulationDataStreamer) – The simulation data streamer object.
starting_funds (float) – The funds with which the simulation will begin.
transaction_cost (float) – The cost of each transaction.
starting_positions (dict, optional, default None) – A dictionary of the starting positions, mapping each account to a dictionary of
AContracttoPosition.
-
property
acc_cash¶ The total funds available across all accounts.
-
property
datetime¶ Server date and time.
-
property
trades¶ Returns all trades placed in the current session.
-
property
open_trades¶ Returns all currently open trades placed in the ongoing session.
-
sleep(secs)¶ Allows the server to deliver data.
-
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.
-
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
Tradeand aTradeStatusas its sole positional arguments.fn_kwargs (dict) – The keyword arguments to pass to the callback function along with the positional arguments.
-
subscribe_to_position_updates(func, fn_kwargs=None)¶ Subscribe to receiving position updates.
- Parameters
func (Callable) – The callback function. It must accept a
Positionas its sole positional argument.fn_kwargs (dict) – The keyword arguments to pass to the callback function along with the positional arguments.
-
place_trade(trade, *args, trade_execution_price=None, trade_execution_size=None, **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
-
get_position(contract, *args, account=None, **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
-
get_transaction_fee()¶ Request the broker transaction cost.
- Returns
The cost per transaction.
- Return type
float