Broker
The broker is the component that handles the placed orders, either real or simulated during a back-test.
It is also the component owns the Account object.
API¶
The Broker base class defines the interface that all broker implementations must follow. The two core methods are:
place_orders(orders: list[Order])— submit one or more orders to the broker. These orders are placed at the real broker which will likely sent them to an exchange.sync(event: Event) -> Account— synchronize the broker state with the latest market event and the real trading account state. Returns the updated Account reflecting cash, positions, open orders, and trades.
asset = rq.Stock("ABC")
order = rq.Order(asset, size=Decimal(100), limit=50.0)
broker.place_orders([order])
account = broker.sync(event)
print("trading price:", event.get_price(asset), "\n")
print(account)trading price: 49.0
buying power : 995,100@USD
cash : 995,100@USD
equity : 1,000,000@USD
positions : 100@ABC
trades : 1
mkt value : 4,900@USD
orders : none
last update : 2026-08-14 09:40:07.755341+00:00
Most users will not implement Broker directly but instead use SimBroker for back-testing or a third-party live broker.
SimBroker¶
The default broker for back-testing is the SimBroker (short for Simulated Broker). It has several configuration parameters and can be subclassed to change even more of its behavior.
from datetime import timezone
from roboquant import SimBroker, USD
broker = SimBroker(
deposit = 1_000_000@USD, # initial available cash for trading
price_type = "OPEN", # what price type to use, fe. OPEN, ASK, CLOSE
slippage= 0.0, # what price slippage to apply, 0.01 is 1%
timezone = timezone.utc, # what timezone to use for validating DAY orders
fee = 0@USD # what additional fee/commission to apply per trade
)Some of the implemented logic that might not be obvious at first:
When
place_orders()is invoked, orders are given anid. However the orders are NOT yet executed. That happens earliest in the next step of the run when thesync()method is invoked. So orders places at timet, will be earliest executed at timet+1.If there is no available price for an asset in the event, the corresponding orders will not be executed. They will stay in open state until a price becomes available.
Only once there is a price available, the DAY time-in-force policy is started.
Third party Brokers¶
Looks at Alpaca, IBKR and Crypto for more details about third party brokers.