Skip to main content

nautilus_trading/
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//! Trading strategy machinery and orchestration [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-trading` crate provides core trading capabilities including:
19//!
20//! - **Forex sessions**: Market session time calculations and timezone handling.
21//!
22//! # NautilusTrader
23//!
24//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
25//! engine for multi-asset, multi-venue trading systems.
26//!
27//! The system spans research, deterministic simulation, and live execution within a single
28//! event-driven architecture, providing research-to-live semantic parity.
29//!
30//! # Feature Flags
31//!
32//! This crate provides feature flags to control source code inclusion during compilation,
33//! depending on the intended use case, i.e. whether to provide Python bindings
34//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
35//! or as part of a Rust only build.
36//!
37//! - `examples`: Enables example strategies (e.g. `EmaCross`) for backtesting and demos.
38//! - `defi`: Enables DeFi (Decentralized Finance) support.
39//! - `high-precision`: Enables [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode) to use 128-bit value types.
40//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
41//! - `extension-module`: Builds the crate as a Python extension module.
42
43#![warn(rustc::all)]
44#![warn(clippy::pedantic)]
45#![deny(unsafe_code)]
46#![deny(unsafe_op_in_unsafe_fn)]
47#![deny(nonstandard_style)]
48#![deny(missing_debug_implementations)]
49#![deny(clippy::missing_errors_doc)]
50#![deny(clippy::missing_panics_doc)]
51#![deny(rustdoc::broken_intra_doc_links)]
52#![allow(
53    clippy::similar_names,
54    reason = "trading domain terms such as side/size and call/put identifiers are intentionally parallel"
55)]
56#![allow(
57    clippy::manual_let_else,
58    reason = "match and if-let early returns are consistent with surrounding trading flow code"
59)]
60#![allow(
61    clippy::redundant_closure_for_method_calls,
62    reason = "matches the Rust 1.94 ICE workaround in the workspace lint table"
63)]
64#![allow(
65    clippy::cast_lossless,
66    clippy::cast_possible_truncation,
67    clippy::cast_possible_wrap,
68    clippy::cast_precision_loss,
69    clippy::cast_sign_loss,
70    reason = "trading algorithms and examples cast between raw quantities, time intervals, and float signals"
71)]
72#![allow(
73    clippy::missing_fields_in_debug,
74    reason = "manual Debug impls intentionally omit verbose runtime state"
75)]
76#![allow(
77    clippy::struct_excessive_bools,
78    reason = "strategy config and state structs mirror existing trading and Python surfaces"
79)]
80#![allow(
81    clippy::too_many_lines,
82    reason = "strategy and algorithm dispatch flows exceed the default threshold by design"
83)]
84#![allow(
85    clippy::match_wildcard_for_single_variants,
86    reason = "wildcard arms guard against future enum variants in trading dispatch"
87)]
88#![cfg_attr(
89    test,
90    allow(
91        clippy::default_trait_access,
92        clippy::float_cmp,
93        reason = "trading tests assert exact float state transitions and build typed fixtures"
94    )
95)]
96
97mod macros;
98
99#[doc(hidden)]
100pub mod _macro_reexports {
101    pub use nautilus_common::actor::{DataActorCore, DataActorNative};
102}
103
104pub mod algorithm;
105pub mod sessions;
106pub mod strategy;
107
108#[cfg(feature = "examples")]
109pub mod examples;
110
111pub use algorithm::{
112    ExecutionAlgorithm, ExecutionAlgorithmConfig, ExecutionAlgorithmCore, ExecutionAlgorithmNative,
113    ImportableExecAlgorithmConfig, TwapAlgorithm, TwapAlgorithmConfig,
114};
115pub use strategy::{
116    ImportableStrategyConfig, Strategy, StrategyConfig, StrategyCore, StrategyNative,
117};
118
119#[cfg(feature = "python")]
120pub mod python;