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

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:

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:00
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.

Some of the implemented logic that might not be obvious at first:

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.