Skip to main content

nautilus_model/
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 domain model for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-model` crate provides a type-safe domain model that forms the backbone of the
19//! framework and can serve as the foundation for building algorithmic trading systems.
20//!
21//! # NautilusTrader
22//!
23//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
24//! engine for multi-asset, multi-venue trading systems.
25//!
26//! The system spans research, deterministic simulation, and live execution within a single
27//! event-driven architecture, providing research-to-live semantic parity.
28//!
29//! # Feature Flags
30//!
31//! This crate provides feature flags to control source code inclusion during compilation,
32//! depending on the intended use case, i.e. whether to provide Python bindings
33//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
34//! or as part of a Rust only build.
35//!
36//! - `arrow`: Enables Apache Arrow schema and `RecordBatch` registries for custom data.
37//! - `defi`: Enables the DeFi (Decentralized Finance) domain model.
38//! - `extension-module`: Builds as a Python extension module.
39//! - `ffi`: Enables the C foreign function interface (FFI) from
40//!   [cbindgen](https://crates.io/crates/cbindgen).
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//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
45//! - `python-arrow`: Enables Python bindings together with `PyArrow` `RecordBatch` bridging.
46//! - `test-support`: Enables test fixtures, builders, specs, and defaults.
47
48#![warn(rustc::all)]
49#![warn(clippy::pedantic)]
50#![deny(unsafe_code)]
51#![deny(unsafe_op_in_unsafe_fn)]
52#![deny(nonstandard_style)]
53#![deny(missing_debug_implementations)]
54#![deny(clippy::missing_errors_doc)]
55#![deny(clippy::missing_panics_doc)]
56#![deny(rustdoc::broken_intra_doc_links)]
57#![cfg_attr(test, allow(clippy::large_stack_arrays))]
58#![allow(
59    clippy::inline_always,
60    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
61)]
62#![allow(
63    clippy::manual_let_else,
64    reason = "match can be clearer than let-else for some patterns"
65)]
66#![allow(
67    clippy::float_cmp,
68    reason = "numeric domain crate: float equality comparisons are pervasive and intentional"
69)]
70#![allow(
71    clippy::unsafe_derive_deserialize,
72    reason = "serde derives on types with unsafe methods for FFI are intentional"
73)]
74#![allow(
75    clippy::cast_possible_truncation,
76    clippy::cast_possible_wrap,
77    clippy::cast_sign_loss,
78    clippy::cast_precision_loss,
79    reason = "numeric domain crate: casts are fundamental to fixed-point arithmetic and type conversions"
80)]
81#![allow(
82    clippy::trivially_copy_pass_by_ref,
83    reason = "changing pass-by-ref to pass-by-value would break FFI and Python binding signatures"
84)]
85#![allow(
86    clippy::similar_names,
87    reason = "domain terminology creates naturally similar names (bid/ask, base/quote)"
88)]
89#![allow(
90    clippy::too_many_lines,
91    reason = "trading domain functions with match arms over many variants are complex by nature"
92)]
93#![allow(
94    clippy::match_same_arms,
95    reason = "identical match arms are sometimes intentional for documentation and readability"
96)]
97#![allow(
98    clippy::unused_self,
99    reason = "PyO3 methods require &self for Python binding even when Rust impl does not use it"
100)]
101#![allow(
102    clippy::many_single_char_names,
103    reason = "math formulas (Black-Scholes, Greeks) use standard single-character variable names"
104)]
105#![allow(
106    clippy::large_types_passed_by_value,
107    reason = "PyO3 methods require owned values extracted from Python objects"
108)]
109#![allow(
110    clippy::assert_is_empty,
111    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
112)]
113// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
114// macro expansion; an item-level `allow` cannot reach the expansion
115#![allow(clippy::clone_on_copy)]
116
117// Re-exported so `enum_strum_serde!` can reach serde through `$crate`, which works in a consumer
118// that renames its serde dependency or does not depend on it directly.
119#[doc(hidden)]
120pub use serde as __serde;
121
122pub mod accounts;
123pub mod currencies;
124pub mod data;
125pub mod enums;
126pub mod events;
127pub mod identifiers;
128pub mod instruments;
129pub mod macros;
130pub mod orderbook;
131pub mod orders;
132pub mod position;
133pub mod reports;
134pub mod types;
135pub mod venues;
136
137pub(crate) mod expressions;
138
139#[cfg(feature = "ffi")]
140pub mod ffi;
141
142#[cfg(feature = "python")]
143pub mod python;
144
145#[cfg(any(test, feature = "test-support"))]
146pub mod stubs;
147
148#[cfg(feature = "defi")]
149pub mod defi;