Skip to main content

nautilus_execution/
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//! Order execution system for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-execution` crate provides an order execution system that handles the complete
19//! order lifecycle from submission to fill processing. This includes sophisticated order matching,
20//! execution venue integration, and advanced order type emulation:
21//!
22//! - **Execution engine**: Central orchestration of order routing and position management.
23//! - **Order matching engine**: High-fidelity market simulation for backtesting and paper trading.
24//! - **Order emulator**: Advanced order types not natively supported by venues (trailing stops, contingent orders).
25//! - **Execution clients**: Abstract interfaces for connecting to trading venues and brokers.
26//! - **Order manager**: Local order lifecycle management and state tracking.
27//! - **Matching core**: Low-level order book and price-time priority matching algorithms.
28//! - **Fee and fill models**: Configurable execution cost simulation and realistic fill behavior.
29//!
30//! The crate supports both live trading environments (with real execution clients) and simulated
31//! environments (with matching engines), making it suitable for production trading, strategy
32//! development, and backtesting.
33//!
34//! # NautilusTrader
35//!
36//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
37//! engine for multi-asset, multi-venue trading systems.
38//!
39//! The system spans research, deterministic simulation, and live execution within a single
40//! event-driven architecture, providing research-to-live semantic parity.
41//!
42//! # Feature Flags
43//!
44//! This crate provides feature flags to control source code inclusion during compilation,
45//! depending on the intended use case, i.e. whether to provide Python bindings
46//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
47//! or as part of a Rust only build.
48//!
49//! - `extension-module`: Builds as a Python extension module.
50//! - `high-precision`: Enables
51//!   [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation/#precision-mode)
52//!   to use 128-bit value types.
53//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
54//! - `simulation`: Enables deterministic simulation testing with
55//!   [MadSim](https://crates.io/crates/madsim).
56
57#![warn(rustc::all)]
58#![warn(clippy::pedantic)]
59#![deny(unsafe_code)]
60#![deny(unsafe_op_in_unsafe_fn)]
61#![deny(nonstandard_style)]
62#![deny(missing_debug_implementations)]
63#![deny(clippy::missing_errors_doc)]
64#![deny(clippy::missing_panics_doc)]
65#![deny(rustdoc::broken_intra_doc_links)]
66#![allow(
67    clippy::similar_names,
68    reason = "execution domain terms such as ts_event/ts_init are intentionally parallel"
69)]
70#![allow(
71    clippy::cast_lossless,
72    clippy::cast_possible_truncation,
73    clippy::cast_possible_wrap,
74    clippy::cast_precision_loss,
75    clippy::cast_sign_loss,
76    reason = "execution math casts between i64/u64/usize/f64 with values bounded by domain ranges"
77)]
78#![allow(
79    clippy::must_use_candidate,
80    reason = "execution accessors and constructors are pervasive; #[must_use] noise is not warranted"
81)]
82#![allow(
83    clippy::unused_self,
84    reason = "engine and matching operations take &self for method-style organization"
85)]
86#![allow(
87    clippy::large_types_passed_by_value,
88    reason = "command and report value types are intentionally moved through dispatch"
89)]
90#![allow(
91    clippy::unsafe_derive_deserialize,
92    reason = "config types deserialize plain field values; unrelated unsafe impls are sound"
93)]
94#![allow(
95    clippy::missing_fields_in_debug,
96    reason = "manual Debug impls intentionally omit verbose internal state"
97)]
98#![allow(
99    clippy::struct_excessive_bools,
100    reason = "config and snapshot structs mirror existing Python configuration surfaces"
101)]
102#![allow(
103    clippy::too_many_lines,
104    reason = "engine and matching dispatch functions exceed the default threshold by design"
105)]
106#![allow(
107    clippy::inline_always,
108    reason = "hot-path matching engine functions are intentionally always inlined"
109)]
110#![allow(
111    clippy::match_same_arms,
112    reason = "explicit per-variant arms document order/event dispatch even when bodies coincide"
113)]
114#![allow(
115    clippy::match_wildcard_for_single_variants,
116    reason = "wildcard arms guard against future enum variants in command dispatch"
117)]
118#![allow(
119    clippy::manual_let_else,
120    reason = "match-with-early-return is consistent with surrounding engine and reconciliation code"
121)]
122#![allow(
123    clippy::single_match_else,
124    reason = "two-arm matches are consistent with surrounding command and event dispatch"
125)]
126#![allow(
127    clippy::assert_is_empty,
128    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
129)]
130#![cfg_attr(
131    test,
132    allow(
133        clippy::default_trait_access,
134        clippy::float_cmp,
135        clippy::should_panic_without_expect,
136        clippy::unreadable_literal,
137        clippy::used_underscore_binding,
138        reason = "execution tests assert exact float outputs and use loose patterns for fixture setup"
139    )
140)]
141
142pub mod client;
143pub mod engine;
144pub mod matching_core;
145pub mod matching_engine;
146pub mod models;
147pub mod order_emulator;
148pub mod order_manager;
149pub mod protection;
150pub mod reconciliation;
151pub mod trailing;
152
153#[cfg(feature = "python")]
154pub mod python;