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