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