Implementation:Nautechsystems Nautilus trader BacktestVenueConfig Init
| Field | Value |
|---|---|
| sources | https://github.com/nautechsystems/nautilus_trader, https://nautilustrader.io/docs/ |
| domains | backtesting, venue-simulation, configuration-management |
| last_updated | 2026-02-10 12:00 GMT |
Overview
Concrete tool for declarative simulated venue configuration provided by NautilusTrader.
Description
BacktestVenueConfig is a frozen, immutable configuration dataclass that captures every parameter needed to construct a simulated trading venue inside the NautilusTrader backtest engine. It inherits from NautilusConfig and uses msgspec for high-performance serialization.
The class defines a comprehensive set of fields covering:
- Venue identity -- the venue name.
- Account semantics -- OMS type (NETTING or HEDGING), account type (CASH or MARGIN), starting balances, base currency, leverage, and margin model.
- Pluggable models -- fill model, fee model, latency model, and simulation modules, all specified as importable configurations.
- Order book type -- the default book type for the matching engine (L1_MBP, L2_MBP, or L3_MBO).
- Execution behavior flags -- bar execution, trade execution, adaptive bar ordering, liquidity consumption, queue position tracking, price protection, contingent order support, GTD support, reduce-only enforcement, and more.
When passed to a BacktestRunConfig, each BacktestVenueConfig is consumed by the BacktestNode to call engine.add_venue() with the appropriate parameters.
Usage
Import and instantiate BacktestVenueConfig whenever you need to define a simulated exchange for a backtest. Typical scenarios:
- Configuring a single exchange with a cash account for equity backtesting.
- Configuring a margin venue with per-instrument leverage for futures or forex.
- Defining custom fill or fee models for realistic simulation.
- Setting up multiple venues for cross-exchange strategy testing.
Code Reference
Source Location
nautilus_trader/backtest/config.py, lines 50-171.
Signature
class BacktestVenueConfig(NautilusConfig, frozen=True):
name: str
oms_type: OmsType | str
account_type: AccountType | str
starting_balances: list[str]
base_currency: str | None = None
default_leverage: float = 1.0
leverages: dict[str, float] | None = None
margin_model: MarginModelConfig | None = None
modules: list[ImportableActorConfig] | None = None
fill_model: ImportableFillModelConfig | None = None
latency_model: ImportableLatencyModelConfig | None = None
fee_model: ImportableFeeModelConfig | None = None
book_type: BookType | str = "L1_MBP"
routing: bool = False
reject_stop_orders: bool = True
support_gtd_orders: bool = True
support_contingent_orders: bool = True
oto_trigger_mode: OtoTriggerMode | str = "PARTIAL"
use_position_ids: bool = True
use_random_ids: bool = False
use_reduce_only: 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: NonNegativeInt = 0
settlement_prices: dict[InstrumentId, float] | None = None
Import
from nautilus_trader.backtest.config import BacktestVenueConfig
I/O Contract
Inputs
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name |
str |
Yes | -- | The unique name of the venue |
oms_type |
str | Yes | -- | Order management system type: "NETTING" or "HEDGING" |
account_type |
str | Yes | -- | Account type: "CASH" or "MARGIN" |
starting_balances |
list[str] |
Yes | -- | Starting balances, e.g. ["1_000_000 USD"] |
base_currency |
None | No | None |
Base currency; None for multi-currency accounts |
default_leverage |
float |
No | 1.0 |
Default leverage for margin accounts |
leverages |
None | No | None |
Per-instrument leverage overrides |
margin_model |
None | No | None |
Margin model configuration |
modules |
None | No | None |
Simulation modules for the venue |
fill_model |
None | No | None |
Custom fill model |
latency_model |
None | No | None |
Custom latency model |
fee_model |
None | No | None |
Custom fee model |
book_type |
str | No | "L1_MBP" |
Order book type: "L1_MBP", "L2_MBP", or "L3_MBO" |
routing |
bool |
No | False |
Enable multi-venue routing |
reject_stop_orders |
bool |
No | True |
Reject stop orders with in-market trigger prices |
support_gtd_orders |
bool |
No | True |
Support GTD time-in-force orders |
support_contingent_orders |
bool |
No | True |
Support OTO/OCO/OUO contingent orders |
oto_trigger_mode |
str | No | "PARTIAL" |
OTO trigger mode: "PARTIAL" or "FULL" |
use_position_ids |
bool |
No | True |
Generate venue position IDs |
use_random_ids |
bool |
No | False |
Use random UUID4 identifiers |
use_reduce_only |
bool |
No | True |
Honor reduce_only instruction |
use_market_order_acks |
bool |
No | False |
Generate OrderAccepted for market orders |
bar_execution |
bool |
No | True |
Process bars in matching engine |
bar_adaptive_high_low_ordering |
bool |
No | False |
Adaptive bar OHLC processing order |
trade_execution |
bool |
No | True |
Process trades in matching engine |
liquidity_consumption |
bool |
No | False |
Track liquidity consumption per price level |
queue_position |
bool |
No | False |
Track queue position for limit orders |
allow_cash_borrowing |
bool |
No | False |
Allow negative balances on cash accounts |
frozen_account |
bool |
No | False |
Freeze account balances |
price_protection_points |
NonNegativeInt |
No | 0 |
Price boundary in points for protection |
settlement_prices |
None | No | None |
Settlement prices for expiring instruments |
Outputs
| Output | Type | Description |
|---|---|---|
| BacktestVenueConfig instance | BacktestVenueConfig |
Frozen, immutable venue configuration object. Consumed by BacktestRunConfig and ultimately by BacktestNode to build a simulated venue via engine.add_venue().
|
Usage Examples
Basic cash account venue:
from nautilus_trader.backtest.config import BacktestVenueConfig
venue_config = BacktestVenueConfig(
name="SIM",
oms_type="HEDGING",
account_type="CASH",
starting_balances=["1_000_000 USD"],
base_currency="USD",
)
Margin account with custom leverage:
from nautilus_trader.backtest.config import BacktestVenueConfig
venue_config = BacktestVenueConfig(
name="BINANCE",
oms_type="NETTING",
account_type="MARGIN",
starting_balances=["10_000 USDT"],
base_currency="USDT",
default_leverage=10.0,
leverages={"BTCUSDT-PERP.BINANCE": 20.0},
bar_execution=True,
trade_execution=False,
)
Venue with advanced execution options:
from nautilus_trader.backtest.config import BacktestVenueConfig
venue_config = BacktestVenueConfig(
name="CME",
oms_type="NETTING",
account_type="MARGIN",
starting_balances=["500_000 USD"],
base_currency="USD",
default_leverage=5.0,
book_type="L2_MBP",
reject_stop_orders=False,
support_contingent_orders=True,
oto_trigger_mode="FULL",
bar_execution=True,
bar_adaptive_high_low_ordering=True,
liquidity_consumption=True,
queue_position=True,
price_protection_points=10,
)