Skip to main content
It serves as an intermediary between your trading strategy and the market, handling order creation and execution.

Broker Architecture

The Pulse framework uses an abstract base class Broker that defines the core interface, with specific implementations like SimulationBroker for backtesting scenarios. Key responsibilities include:
  • Order Management: Creating and tracking orders
  • Trade Execution: Converting orders into executed trades
  • Order Lifecycle: Managing open orders and their execution timing
  • Market Simulation: Providing realistic trade execution for backtesting
Current implementation of the Broker class is very simple, it only supports creating market orders and does not simulate any slippage or other market conditions. We are working on making the Broker more sophisticated, allowing for different order types and slippage simulation. Also, the idea of Broker is to be easily switched to a live trading environment, so that the same strategy can be used for both backtesting and live trading.

Creating a Simulation Broker

The SimulationBroker is the default implementation used for backtesting. It simulates market order execution by immediately filling all orders at the current market price during each pulse:
Output

Creating Orders

Orders are created using the broker’s create_order() method. This method requires:
  • pulse_index: The current timing context
  • instrument: The financial instrument to trade
  • quantity: Number of contracts (positive for buy, negative for sell)
Let’s create an instrument and place some orders:
Output

Order Execution and Trade Generation

When the broker is pulsed, it executes all open orders and converts them into trades. The SimulationBroker treats all orders as market orders, filling them immediately at the current market price:
Output
In Strategy class you can access the broker instance via self.broker. You can create orders using self.broker.create_order(...) and pulse the broker with self.broker.pulse(pulse_index), or you can call self.create_order(...) which is a shorthand for self.broker.create_order(...). Another way is to call self.buy(...) or self.sell(...) methods, which are also shorthand for creating buy and sell orders respectively.
Last modified on November 4, 2026