Implementation:Nautechsystems Nautilus trader BacktestEngine Add Venue
| Field | Value |
|---|---|
| sources | https://github.com/nautechsystems/nautilus_trader , https://nautilustrader.io/docs/ |
| domains | backtesting, venue simulation, exchange modeling |
| last_updated | 2026-02-10 12:00 GMT |
Overview
Concrete tool for adding a simulated exchange venue to the backtest engine provided by NautilusTrader.
Description
The add_venue method on BacktestEngine constructs a SimulatedExchange with full parameterization of order management, account type, fill/fee/latency/margin models, order book depth, and a rich set of execution behavior flags. It then creates and registers a BacktestExecClient bound to that exchange, wires the client into the kernel's execution engine, and ensures a market-data client exists for the venue. This is the required second step in the backtest setup workflow, after engine construction and before instrument/data addition.
Usage
Call engine.add_venue(...) once per exchange you wish to simulate, before adding instruments or data that belong to that venue.
Code Reference
- Source location:
nautilus_trader/backtest/engine.pyx, lines 490--700 - Signature:
def add_venue(
self,
venue: Venue,
oms_type: OmsType,
account_type: AccountType,
starting_balances: list[Money],
base_currency: Currency | None = None,
default_leverage: Decimal | None = None,
leverages: dict[InstrumentId, Decimal] | None = None,
margin_model: MarginModel = None,
modules: list[SimulationModule] | None = None,
fill_model: FillModel | None = None,
fee_model: FeeModel | None = None,
latency_model: LatencyModel | None = None,
book_type: BookType = BookType.L1_MBP,
routing: bool = False,
reject_stop_orders: bool = True,
support_gtd_orders: bool = True,
support_contingent_orders: bool = True,
oto_trigger_mode: OtoTriggerMode = OtoTriggerMode.PARTIAL,
use_position_ids: bool = True,
use_random_ids: bool = False,
use_reduce_only: bool = True,
use_message_queue: bool = True,
use_market_order_acks: bool = False,
bar_execution: bool = True,
bar_adaptive_high_low_ordering: bool = False,
trade_execution: bool = True,
liquidity_consumption: bool = False,
queue_position: bool = False,
allow_cash_borrowing: bool = False,
frozen_account: bool = False,
price_protection_points=None,
settlement_prices: dict[InstrumentId, float] | None = None,
) -> None
- Import:
from nautilus_trader.backtest.engine import BacktestEngine
from nautilus_trader.model.identifiers import Venue
from nautilus_trader.model.enums import OmsType, AccountType
from nautilus_trader.model.objects import Money
I/O Contract
Inputs:
| Parameter | Type | Required | Description |
|---|---|---|---|
venue |
Venue |
Yes | The venue identifier (must be unique across the engine). |
oms_type |
OmsType |
Yes | Order management system type: HEDGING or NETTING.
|
account_type |
AccountType |
Yes | Account type: CASH or MARGIN.
|
starting_balances |
list[Money] |
Yes | Non-empty list of starting balances (one per currency). |
base_currency |
None | No | Base currency for single-currency accounts; None for multi-currency.
|
default_leverage |
None | No | Default leverage; defaults to 10 for MARGIN, 1 for CASH. |
fill_model |
None | No | Fill model; defaults to FillModel().
|
fee_model |
None | No | Fee model; defaults to MakerTakerFeeModel().
|
latency_model |
None | No | Latency model; None means zero latency.
|
book_type |
BookType |
No | Order book depth: L1_MBP (default), L2_MBP, or L3_MBO.
|
bar_execution |
bool |
No | Whether bars drive market movement (default True).
|
trade_execution |
bool |
No | Whether trades drive market movement (default True).
|
Outputs / Side Effects:
| Output | Type | Description |
|---|---|---|
| None (return) | None |
Method mutates engine state in place. |
| SimulatedExchange | side effect | A new SimulatedExchange is stored in engine._venues[venue].
|
| BacktestExecClient | side effect | Execution client registered with the kernel's execution engine. |
| BacktestMarketDataClient | side effect | Market data client created for the venue if not already present. |
Usage Examples
Adding a simple cash equity venue:
from nautilus_trader.backtest.engine import BacktestEngine
from nautilus_trader.model.identifiers import Venue
from nautilus_trader.model.enums import AccountType, OmsType
from nautilus_trader.model.objects import Money
from nautilus_trader.model.currencies import USD
engine = BacktestEngine()
engine.add_venue(
venue=Venue("SIM"),
oms_type=OmsType.HEDGING,
account_type=AccountType.CASH,
starting_balances=[Money(1_000_000, USD)],
)
Adding a margin venue with custom leverage and fee model:
from decimal import Decimal
from nautilus_trader.backtest.models import MakerTakerFeeModel
engine.add_venue(
venue=Venue("BINANCE"),
oms_type=OmsType.NETTING,
account_type=AccountType.MARGIN,
starting_balances=[Money(100_000, USD)],
default_leverage=Decimal(20),
fee_model=MakerTakerFeeModel(),
bar_execution=True,
trade_execution=False,
)