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