Skip to main content

nautilus_common/
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//! Common componentry for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-common` crate provides shared components and utilities that form the system foundation for
19//! NautilusTrader applications. This includes the actor system, message bus, caching layer, and other
20//! essential services.
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//! - `build-info-event-store`: Includes the event-store backend version in build information logs.
38//! - `defi`: Enables DeFi (Decentralized Finance) support.
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//! - `indicators`: Includes the `nautilus-indicators` crate and indicator utilities.
44//! - `live`: Enables the Tokio async runtime for live trading.
45//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
46//! - `sbe`: Enables Simple Binary Encoding (SBE) serialization support.
47//! - `simulation`: Enables deterministic simulation testing with
48//!   [MadSim](https://crates.io/crates/madsim).
49//! - `tracing-bridge`: Enables the `tracing` subscriber bridge for log integration.
50
51#![warn(rustc::all)]
52#![warn(clippy::pedantic)]
53#![allow(
54    clippy::manual_let_else,
55    clippy::option_if_let_else,
56    clippy::or_fun_call,
57    clippy::redundant_else,
58    clippy::similar_names,
59    clippy::single_match_else,
60    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
61)]
62#![deny(unsafe_code)]
63#![deny(unsafe_op_in_unsafe_fn)]
64#![deny(nonstandard_style)]
65#![deny(missing_debug_implementations)]
66#![deny(clippy::missing_errors_doc)]
67#![deny(clippy::missing_panics_doc)]
68#![deny(rustdoc::broken_intra_doc_links)]
69#![allow(
70    clippy::cast_lossless,
71    clippy::cast_possible_truncation,
72    clippy::cast_possible_wrap,
73    clippy::cast_precision_loss,
74    clippy::cast_sign_loss,
75    reason = "common-layer math casts between i64/u64/usize/f64 with values bounded by domain ranges"
76)]
77#![allow(
78    clippy::must_use_candidate,
79    reason = "common-layer accessors and constructors are pervasive; #[must_use] noise is not warranted"
80)]
81#![allow(
82    clippy::trivially_copy_pass_by_ref,
83    reason = "trait method signatures are dictated by upstream interfaces and Python API parity"
84)]
85#![allow(
86    clippy::unsafe_derive_deserialize,
87    reason = "config types deserialize plain field values; unsafe in unrelated impls is sound"
88)]
89#![allow(
90    clippy::missing_fields_in_debug,
91    reason = "manual Debug impls intentionally omit verbose internal state and handler maps"
92)]
93#![allow(
94    clippy::struct_excessive_bools,
95    clippy::fn_params_excessive_bools,
96    reason = "config structs and constructors mirror existing Python configuration surfaces"
97)]
98#![allow(
99    clippy::too_many_lines,
100    reason = "actor and message bus dispatch functions exceed the default threshold by design"
101)]
102#![allow(
103    clippy::implicit_hasher,
104    reason = "hash maps in public APIs intentionally accept the default hasher"
105)]
106#![allow(
107    clippy::inline_always,
108    reason = "hot-path throttler and clock functions are intentionally always inlined"
109)]
110#![allow(
111    clippy::match_same_arms,
112    reason = "explicit per-variant arms document message dispatch even when bodies coincide"
113)]
114#![allow(
115    clippy::assert_is_empty,
116    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
117)]
118// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
119// macro expansion; an item-level `allow` cannot reach the expansion
120#![allow(clippy::clone_on_copy)]
121#![cfg_attr(
122    test,
123    allow(
124        clippy::default_trait_access,
125        clippy::float_cmp,
126        clippy::no_effect_underscore_binding,
127        clippy::should_panic_without_expect,
128        clippy::unreadable_literal,
129        clippy::unused_self,
130        clippy::used_underscore_binding,
131        reason = "common tests assert exact float outputs and use loose patterns for fixture setup"
132    )
133)]
134
135pub mod actor;
136pub mod cache;
137pub mod calendar;
138pub mod clients;
139pub mod clock;
140pub mod component;
141pub mod config;
142pub mod custom;
143pub mod enums;
144pub mod factories;
145pub mod generators;
146pub mod greeks;
147pub mod logging;
148pub mod messages;
149pub mod msgbus;
150pub mod providers;
151pub mod runner;
152pub mod signal;
153pub mod testing;
154pub mod throttler;
155pub mod timer;
156pub mod xrate;
157
158mod macros;
159
160#[cfg(feature = "live")]
161pub mod live;
162
163#[cfg(feature = "defi")]
164pub mod defi;
165
166#[cfg(feature = "python")]
167pub mod python;
168
169pub mod serialization;