nautilus_backtest/lib.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Backtest engine for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-backtest` crate provides an event-driven backtesting framework that allows
19//! quantitative traders to test and validate trading strategies on historical data with high
20//! fidelity market simulation. The system replicates real market conditions including:
21//!
22//! - Event-driven backtesting engine with simulated exchanges.
23//! - Market data replay with configurable latency and fill models.
24//! - Order matching engines with realistic execution simulation.
25//! - Multi-venue and multi-asset backtesting capabilities.
26//! - Configuration and state management.
27//! - Integration with live trading systems for direct deployment.
28//!
29//! # NautilusTrader
30//!
31//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
32//! engine for multi-asset, multi-venue trading systems.
33//!
34//! The system spans research, deterministic simulation, and live execution within a single
35//! event-driven architecture, providing research-to-live semantic parity.
36//!
37//! # Feature Flags
38//!
39//! This crate provides feature flags to control source code inclusion during compilation,
40//! depending on the intended use case, i.e. whether to provide Python bindings
41//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
42//! or as part of a Rust only build.
43//!
44//! - `examples`: Enables example strategies and the EMA crossover backtest example.
45//! - `mimalloc`: Uses [mimalloc](https://github.com/microsoft/mimalloc) as the global allocator for
46//! bundled Rust examples.
47//! - `defi`: Enables DeFi replay APIs and data-engine routing.
48//! - `streaming`: Enables `persistence` dependency for streaming configuration.
49//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
50//! - `extension-module`: Builds the crate as a Python extension module.
51
52#![warn(rustc::all)]
53#![warn(clippy::pedantic)]
54#![deny(unsafe_code)]
55#![deny(unsafe_op_in_unsafe_fn)]
56#![deny(nonstandard_style)]
57#![deny(missing_debug_implementations)]
58#![deny(clippy::missing_errors_doc)]
59#![deny(clippy::missing_panics_doc)]
60#![deny(rustdoc::broken_intra_doc_links)]
61#![allow(
62 clippy::too_many_lines,
63 reason = "backtest engine, node, and Python registration flows exceed the default threshold by design"
64)]
65#![allow(
66 clippy::assert_is_empty,
67 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
68)]
69// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
70// macro expansion; an item-level `allow` cannot reach the expansion
71#![allow(clippy::clone_on_copy)]
72
73pub mod accumulator;
74pub mod config;
75pub mod data_client;
76pub mod data_iterator;
77#[cfg(feature = "defi")]
78pub mod defi;
79pub mod engine;
80pub mod exchange;
81pub mod execution_client;
82pub mod modules;
83pub mod result;
84
85#[cfg(feature = "streaming")]
86pub mod node;
87
88#[cfg(feature = "python")]
89pub mod python;