Skip to main content

nautilus_live/
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//! Live system node for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The crate provides live event transport, execution state management, and node lifecycle support.
19//!
20//! - [`execution`] supplies adapter-facing order context, failure classification, report filtering,
21//!   event emission, and the execution manager. The manager tracks reconciliation state, requests
22//!   reports for individual checks, and applies startup reconciliation events.
23//! - `node` (with the `node` feature) owns the kernel lifecycle, recurring reconciliation tasks,
24//!   collection deadlines, cancellation, and dispatch through the live event loop.
25//! - [`runner`] routes asynchronous data, execution, system, and timer traffic.
26//!
27//! # NautilusTrader
28//!
29//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
30//! engine for multi-asset, multi-venue trading systems.
31//!
32//! The system spans research, deterministic simulation, and live execution within a single
33//! event-driven architecture, providing research-to-live semantic parity.
34//!
35//! # Feature Flags
36//!
37//! This crate provides feature flags to control source code inclusion during compilation,
38//! depending on the intended use case, i.e. whether to provide Python bindings
39//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
40//! or as part of a Rust only build.
41//!
42//! - `defi`: Enables DeFi (Decentralized Finance) support.
43//! - `examples`: Enables example strategies and testkit support for live nodes.
44//! - `extension-module`: Builds as a Python extension module.
45//! - `fuzz`: Provides shared libFuzzer integration for adapter fuzz binaries.
46//! - `node` (default): Enables the live node, builder, configuration, and system-kernel dependencies.
47//! - `plugin` (default): Keeps compatibility stubs for plug-in config validation.
48//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs) and auto-enables `node` and
49//!   `streaming`.
50//! - `simulation`: Enables deterministic simulation testing with
51//!   [MadSim](https://crates.io/crates/madsim).
52//! - `streaming`: Enables the `nautilus-persistence` dependency for streaming configuration and
53//!   requires `node`.
54//! - `test-support`: Enables engine-wired execution support for adapter integration tests.
55//!
56//! # Lean adapter builds
57//!
58//! Adapters and other consumers that only need the async event emitter, runner, and
59//! `ExecutionClientCore` re-export can opt out of the full kernel by disabling the
60//! `node` feature:
61//!
62//! ```toml
63//! nautilus-live = { workspace = true, default-features = false }
64//! ```
65//!
66//! With `node` disabled, execution support (including the manager), run-to-completion
67//! reconciliation, the runner, socket controls, and task support remain available. This skips
68//! the transitive dependencies on `nautilus-system`, `nautilus-trading`,
69//! `nautilus-portfolio`, `nautilus-risk`, and `nautilus-data`.
70//!
71//! # Plug-in support
72//!
73//! The open-source live crate does not host dynamic plug-ins directly.
74//! `nautilus-plugin` is the public guest ABI crate, while host-side loading,
75//! vtables, bridge adapters, and server policy belong to the host-side plug-in
76//! integration.
77//! A non-empty `LiveNodeConfig.plugins` list is rejected unless an application
78//! provides that host-side integration.
79//!
80//! ```toml
81//! nautilus-live = { workspace = true, default-features = false, features = ["node"] }
82//! ```
83//!
84//! With `plugin` disabled, the compatibility `plugin` module is removed. A
85//! non-empty `LiveNodeConfig.plugins` list is rejected under this configuration
86//! as well.
87
88#![warn(rustc::all)]
89#![warn(clippy::pedantic)]
90#![deny(unsafe_code)]
91#![deny(unsafe_op_in_unsafe_fn)]
92#![deny(nonstandard_style)]
93#![deny(missing_debug_implementations)]
94#![deny(clippy::missing_errors_doc)]
95#![deny(clippy::missing_panics_doc)]
96#![deny(rustdoc::broken_intra_doc_links)]
97#![allow(
98    clippy::similar_names,
99    reason = "timing and plug-in identifiers such as elapsed_ms/elapsed_ns and loaded/loader are intentionally parallel"
100)]
101#![allow(
102    clippy::single_match_else,
103    reason = "match can be clearer than if-let-else for some reconciliation state transitions"
104)]
105#![allow(
106    clippy::too_many_lines,
107    reason = "live node lifecycle and reconciliation flows exceed the default threshold by design"
108)]
109#![allow(
110    clippy::unsafe_derive_deserialize,
111    reason = "config types deserialize plain field values; unsafe in unrelated impls is sound"
112)]
113#![allow(
114    clippy::assert_is_empty,
115    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
116)]
117// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
118// macro expansion; an item-level `allow` cannot reach the expansion
119#![allow(clippy::clone_on_copy)]
120
121pub mod book;
122pub mod execution;
123pub mod runner;
124pub mod socket;
125pub mod task;
126
127#[cfg(feature = "fuzz")]
128#[doc(hidden)]
129pub mod fuzz;
130
131#[cfg(feature = "fuzz")]
132#[doc(hidden)]
133pub use fuzz::Corpus;
134
135#[cfg(feature = "node")]
136pub mod node;
137
138#[cfg(feature = "python")]
139pub mod python;
140
141#[cfg(feature = "test-support")]
142pub mod testing;
143
144mod dispatch;
145
146// Re-exports for adapters
147pub use execution::{emitter, emitter::ExecutionEventEmitter, manager};
148pub use nautilus_common::factories::OrderEventFactory;
149pub use nautilus_execution::client::core::ExecutionClientCore;
150#[cfg(feature = "plugin")]
151pub use node::plugin;
152#[cfg(feature = "node")]
153pub use node::{builder, config};
154pub use socket::{
155    SocketControl, SocketControlFactory, SocketReconnectLookup, SocketReconnectRegistry,
156    SocketReconnectRequestOutcome,
157};