Broker
Overview¶
The broker is the component responsible for executing orders. It can be a real broker that trades live in the market, or a simulated one used during back-testing. It also manages the lifecycle of orders — from submission, to (partial) fills, to expiration or cancellation.
It is also the component that owns and manages the Account object. The Account serves as the authoritative record of the broker’s current state — including available cash, open positions, pending orders, and completed trades. Every time the broker is synchronized via sync(), this account is updated and returned, so you can always inspect the latest trading state.
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 roboquant broker state with the real trading account state. Returns the updated Account reflecting cash, positions, open orders, and trades.
Example¶
buying power : 1,000,000@USD
cash : 1,000,000@USD
equity : 1,000,000@USD
positions : none
trades : 0
mkt value : 0@USD
orders : none
last update : 2026-10-01 04:48:11.062436+00:00asset = 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-10-01 04:48:11.062436+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 for the underlying asset, the DAY time-in-force policy is started.
Third party Brokers¶
Looks at Alpaca, IBKR, Crypto and MetaTrader for more details about third party brokers.
Live Broker¶
If you are developing your own Broker implementation, you can use the LiveBroker as a base-class.
Te main work is the mapping the roboquant classes like Order and Position to the broker you want to
integrate with.
To get started, best to look at some of the existing implementations like the AlpacaBroker.