NautilusTrader
Concepts
These docs track the unreleased nightly build and may change without notice. Switch to the latest stable docs.

Rust

Nautilus has a complete Rust implementation under the crates/ directory. You can write actors, strategies, run backtests, and trade live without Python. The domain model is shared across all paths, and the v2 PyO3 path runs Python strategies on the Rust engine directly.

The Rust API is under active development. Method signatures and trait requirements may change between releases.

System implementations

Nautilus has three implementations. Understanding where each stands helps you choose the right one for your use case.

  • v1 legacy: Cython/Python classes under nautilus_trader/. Fully featured with the broadest component coverage.
  • v2 Rust: Pure Rust under crates/. Runs without Python.
  • v2 PyO3: Python user-components (actors, strategies) running on the Rust core via PyO3 bindings. Combines Python convenience with Rust engine performance.

Capability matrix

Componentv1 legacy (Cython)v2 Rustv2 PyO3 (Python on Rust)
Strategy
Actor
DataEngine
ExecutionEngine
RiskEngine
BacktestEngine
BacktestNode
LiveNode
OrderEmulator
Matching engine
Portfolio
Accounts
Cache
MessageBus
Data catalog
Indicators
Exec algorithmsTWAPTWAPTWAP
Controller--
Tearsheets--
Config serialization--

Adapters

Adapterv1 legacy (Cython)v2 Rustv2 PyO3
Architect AX
Betfair
Binance
BitMEX
Bybit
Databento
Deribit
dYdX
Hyperliquid
Interactive Brokers--
Kraken
OKX
Polymarket
Sandbox
Tardis

Choosing a path

  • v1 legacy is the most complete today. Use it if you need the Controller, tearsheets, Interactive Brokers, or config serialization.
  • v2 Rust gives native performance without a Python runtime. All core trading functionality is available. Use it for latency-sensitive deployments or teams that prefer a compiled language.
  • v2 PyO3: Python user-components (actors, strategies) run on the Rust core engine with Rust performance for data processing and execution, while keeping the Python authoring experience.

Project setup

The Nautilus crates are published to crates.io. Add them to your Cargo.toml:

[dependencies]
nautilus-backtest = "0.59"
nautilus-common = "0.59"
nautilus-execution = "0.59"
nautilus-model = { version = "0.59", features = ["stubs"] }
nautilus-trading = { version = "0.59", features = ["examples"] }

anyhow = "1"
log = "0.4"

For live trading, add the live crate and the adapter for your venue:

[dependencies]
nautilus-live = "0.59"
nautilus-okx = "0.59"

To track the latest development branch, point all Nautilus dependencies at the same git source to avoid type mismatches between crates.io and git versions:

[dependencies]
nautilus-backtest = { git = "https://github.com/nautechsystems/nautilus_trader.git", branch = "develop" }
nautilus-common = { git = "https://github.com/nautechsystems/nautilus_trader.git", branch = "develop" }
nautilus-execution = { git = "https://github.com/nautechsystems/nautilus_trader.git", branch = "develop" }
nautilus-model = { git = "https://github.com/nautechsystems/nautilus_trader.git", branch = "develop", features = ["stubs"] }
nautilus-trading = { git = "https://github.com/nautechsystems/nautilus_trader.git", branch = "develop", features = ["examples"] }

The minimum supported Rust version (MSRV) is 1.96.0.

Feature flags

FlagCrateEffect
high-precisionnautilus-model16-digit fixed precision (default is 9). Required for crypto.
stubsnautilus-modelTest instrument stubs (audusd_sim, etc.).
examplesnautilus-tradingExample strategies (EmaCross, GridMarketMaker).
streamingnautilus-backtestCatalog‑based data streaming via BacktestNode.
definautilus-modelDeFi data types. Implies high-precision.

Standard 9-digit precision handles most traditional finance instruments. Enable high-precision for crypto venues where prices can have many decimal places (e.g. 0.00000001).

Actors

An actor receives market data, custom data/signals, and system events but does not manage orders. Implement the DataActor trait and use nautilus_actor! to wire your DataActorCore field into the runtime contract. Your struct must also implement Debug (required by the blanket Component impl). User code normally uses the DataActor facade methods for subscriptions, cache access, and clock access.

Handler methods

Override any handler on the DataActor trait to receive the corresponding data or event. All handlers have default no-op implementations, so you only override what you need.

HandlerReceives
on_startActor started.
on_stopActor stopped.
on_quoteQuoteTick
on_tradeTradeTick
on_barBar
on_book_deltasOrderBookDeltas
on_bookOrderBook (at interval)
on_instrumentInstrumentAny
on_mark_priceMarkPriceUpdate
on_index_priceIndexPriceUpdate
on_funding_rateFundingRateUpdate
on_option_greeksOptionGreeks
on_option_chainOptionChainSlice
on_instrument_statusInstrumentStatus
on_order_filledOrderFilled
on_order_canceledOrderCanceled
on_time_eventTimeEvent

For a step-by-step walkthrough, see the Write an Actor (Rust) how-to guide. For a complete example, see BookImbalanceActor.

Strategies

A strategy extends an actor with order management. Implement DataActor for data handling and use nautilus_strategy! to wire your StrategyCore field into the strategy runtime contract. StrategyCore wraps DataActorCore and adds an OrderFactory, OrderManager, and portfolio integration.

Order management

The Strategy trait provides order methods through StrategyCore:

MethodAction
submit_orderSubmit a new order to the venue.
submit_order_listSubmit a list of contingent orders.
modify_orderModify price, quantity, or trigger price.
cancel_orderCancel a specific order.
cancel_ordersCancel a filtered set of orders.
cancel_all_ordersCancel all orders for an instrument.
close_positionClose a position with a market order.
close_all_positionsClose all open positions.

The OrderApi (accessed via self.order()) builds orders and order lists: generate_client_order_id, generate_order_list_id, market, limit, stop_market, stop_limit, market_to_limit, market_if_touched, limit_if_touched, trailing_stop_market, trailing_stop_limit, bracket, and create_list.

Core wiring macros

Rust actors and strategies keep their runtime core as a struct field. The macros tell the traits where that field lives.

MacroCore fieldGenerates
nautilus_actor!(Type)DataActorCoreNative runtime wiring.
nautilus_strategy!(Type)StrategyCoreNative runtime wiring and Strategy.

Both macros expect a field named core; pass a field name as the second argument when needed. They do not make the actor or strategy deref to its core. Normal code uses facade methods such as clock(), cache(), order(), and portfolio().

Native traits

Use facade methods by default: clock(), cache(), order(), and portfolio(). DataActorNative and StrategyNative are for native-only access below that facade. Treat them as explicit escape hatches.

Authoring pathUse native traits?Use this API
Native Rust binaryOnly when neededFacades, then native traits
Rust launched from PythonOnly when neededSame as native Rust
Python‑authored componentNoFacades only
Plug‑in‑compatible codeNoFacades only

Native traits expose borrowed core state, Rc<RefCell<_>>, and runtime references. Use them only for performance-sensitive native paths or host integration internals. Do not use them in Python-authored or plug-in-compatible strategies and actors, because those types do not cross those boundaries.

For a step-by-step walkthrough, see the Write a Strategy (Rust) how-to guide. For complete examples, see EmaCross and GridMarketMaker.

Running Rust components

Rust strategies and actors can run through three paths. The examples below use strategies, but the same pattern applies to actors via add_actor (pure Rust) and add_native_actor (from Python).

Pure Rust

Write your strategy and main function in Rust, then build a standalone binary with cargo build. This path requires no Python runtime.

let strategy = GridMarketMaker::new(config);
node.add_strategy(strategy)?;
node.run().await?;

See Run Live Trading (Rust) for a full walkthrough.

Native config from Python

Pass a type name and config to add_native_strategy to register a built-in Rust strategy from Python. The Rust side constructs the strategy and registers it with the engine. Python provides the configuration; all execution happens in Rust.

from nautilus_trader.core.nautilus_pyo3.trading import GridMarketMakerConfig

config = GridMarketMakerConfig(
    instrument_id=InstrumentId.from_str("BTC-USDT-SWAP.OKX"),
    max_position=Quantity.from_str("10.0"),
    trade_size=Quantity.from_str("0.1"),
    num_levels=5,
    grid_step_bps=15,
)

node.add_native_strategy("GridMarketMaker", config)

Built-in strategy configs:

ConfigStrategy
CompositeMarketMakerConfigCompositeMarketMaker
DeltaNeutralVolConfigDeltaNeutralVol
EmaCrossConfigEmaCross
ExecTesterConfigExecTester
GridMarketMakerConfigGridMarketMaker
HurstVpinDirectionalConfigHurstVpinDirectional

Built-in actor configs (via add_native_actor):

ConfigActor
BookImbalanceActorConfigBookImbalanceActor
DataTesterConfigDataTester

Users who compile from source can add their own native components to this path. Add a #[pyclass] config, a register_* function, and a match arm in native_strategy_register or native_actor_register. The component then works from Python without PyO3 wrappers on the type itself.

Plugin loading

Use add_plugin or LiveNodeConfig.plugins for Rust components built as cdylib crates. The plug-in manifest supplies the component kind, so the host needs only the library path, manifest type name, and instance config.

Backtesting

For annotated walkthroughs of both APIs, see the Run a Backtest (Rust) how-to guide.

BacktestEngine (low-level API)

Construct the engine, add venues and instruments, load data, register strategies, and run. See the full working example:

cargo run -p nautilus-backtest --features examples --example engine-ema-cross

Source: crates/backtest/examples/engine_ema_cross.rs

BacktestNode (high-level API)

Loads data from a ParquetDataCatalog and supports streaming in configurable chunk sizes. Requires the streaming feature on nautilus-backtest. See the full working example:

cargo run -p nautilus-backtest --features examples,streaming --example node-ema-cross

Source: crates/backtest/examples/node_ema_cross.rs

Live trading

For an annotated walkthrough, see the Run Live Trading (Rust) how-to guide.

The LiveNode connects to real venues through adapter clients. The builder pattern configures data and execution clients, then run() starts the async event loop. Each adapter provides its own factory and config types.

AdapterExample
Architect AXcrates/adapters/architect_ax/examples/
Betfaircrates/adapters/betfair/examples/
Binancecrates/adapters/binance/examples/
BitMEXcrates/adapters/bitmex/examples/
Blockchaincrates/adapters/blockchain/examples/
Bybitcrates/adapters/bybit/examples/
Databentocrates/adapters/databento/examples/
Deribitcrates/adapters/deribit/examples/
dYdXcrates/adapters/dydx/examples/
Hyperliquidcrates/adapters/hyperliquid/examples/
Krakencrates/adapters/kraken/examples/
OKXcrates/adapters/okx/examples/
Polymarketcrates/adapters/polymarket/examples/
Sandboxcrates/adapters/sandbox/examples/
Tardiscrates/adapters/tardis/examples/

Most adapters include node_data_tester.rs and node_exec_tester.rs examples. These test data requests, streaming, and order execution against live venues.

On this page