Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

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:

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:

Third party Brokers

Looks at Alpaca, IBKR and Crypto for more details about third party brokers.