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//! - `defi`: Enables DeFi (Decentralized Finance) support.
38//! - `examples`: Enables example strategies such as `EmaCross` for backtesting and demos.
39//! - `extension-module`: Builds as a Python extension module.
40//! - `high-precision`: Enables
41//!   [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation/#precision-mode)
42//!   to use 128-bit value types.
43//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
44
45#![warn(rustc::all)]
46#![warn(clippy::pedantic)]
47#![allow(
48    clippy::manual_let_else,
49    clippy::option_if_let_else,
50    clippy::or_fun_call,
51    clippy::redundant_else,
52    clippy::similar_names,
53    clippy::single_match_else,
54    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
55)]
56#![deny(unsafe_code)]
57#![deny(unsafe_op_in_unsafe_fn)]
58#![deny(nonstandard_style)]
59#![deny(missing_debug_implementations)]
60#![deny(clippy::missing_errors_doc)]
61#![deny(clippy::missing_panics_doc)]
62#![deny(rustdoc::broken_intra_doc_links)]
63#![allow(
64    clippy::cast_lossless,
65    clippy::cast_possible_truncation,
66    clippy::cast_possible_wrap,
67    clippy::cast_precision_loss,
68    clippy::cast_sign_loss,
69    reason = "trading algorithms and examples cast between raw quantities, time intervals, and float signals"
70)]
71#![allow(
72    clippy::missing_fields_in_debug,
73    reason = "manual Debug impls intentionally omit verbose runtime state"
74)]
75#![allow(
76    clippy::struct_excessive_bools,
77    reason = "strategy config and state structs mirror existing trading and Python surfaces"
78)]
79#![allow(
80    clippy::too_many_lines,
81    reason = "strategy and algorithm dispatch flows exceed the default threshold by design"
82)]
83#![allow(
84    clippy::match_wildcard_for_single_variants,
85    reason = "wildcard arms guard against future enum variants in trading dispatch"
86)]
87#![allow(
88    clippy::assert_is_empty,
89    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
90)]
91// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
92// macro expansion; an item-level `allow` cannot reach the expansion
93#![allow(clippy::clone_on_copy)]
94#![cfg_attr(
95    test,
96    allow(
97        clippy::default_trait_access,
98        clippy::float_cmp,
99        reason = "trading tests assert exact float state transitions and build typed fixtures"
100    )
101)]
102
103mod macros;
104
105#[doc(hidden)]
106pub mod _macro_reexports {
107    pub use nautilus_common::actor::{DataActorCore, DataActorNative};
108}
109
110pub mod algorithm;
111pub mod controller;
112pub mod sessions;
113pub mod strategy;
114
115#[cfg(feature = "examples")]
116pub mod examples;
117
118pub use algorithm::{
119    ExecutionAlgorithm, ExecutionAlgorithmConfig, ExecutionAlgorithmCore, ExecutionAlgorithmNative,
120    ImportableExecutionAlgorithmConfig, TwapAlgorithm, TwapAlgorithmConfig,
121};
122pub use controller::ImportableControllerConfig;
123pub use strategy::{
124    ImportableStrategyConfig, Strategy, StrategyConfig, StrategyCore, StrategyNative,
125};
126
127#[cfg(feature = "python")]
128pub mod python;