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#![allow(
51    clippy::manual_let_else,
52    clippy::option_if_let_else,
53    clippy::or_fun_call,
54    clippy::redundant_else,
55    clippy::similar_names,
56    clippy::single_match_else,
57    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
58)]
59#![deny(unsafe_code)]
60#![deny(unsafe_op_in_unsafe_fn)]
61#![deny(nonstandard_style)]
62#![deny(missing_debug_implementations)]
63#![deny(clippy::missing_errors_doc)]
64#![deny(clippy::missing_panics_doc)]
65#![deny(rustdoc::broken_intra_doc_links)]
66#![cfg_attr(test, allow(clippy::large_stack_arrays))]
67#![allow(
68    clippy::inline_always,
69    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
70)]
71#![allow(
72    clippy::float_cmp,
73    reason = "numeric domain crate: float equality comparisons are pervasive and intentional"
74)]
75#![allow(
76    clippy::unsafe_derive_deserialize,
77    reason = "serde derives on types with unsafe methods for FFI are intentional"
78)]
79#![allow(
80    clippy::cast_possible_truncation,
81    clippy::cast_possible_wrap,
82    clippy::cast_sign_loss,
83    clippy::cast_precision_loss,
84    reason = "numeric domain crate: casts are fundamental to fixed-point arithmetic and type conversions"
85)]
86#![allow(
87    clippy::trivially_copy_pass_by_ref,
88    reason = "changing pass-by-ref to pass-by-value would break FFI and Python binding signatures"
89)]
90#![allow(
91    clippy::too_many_lines,
92    reason = "trading domain functions with match arms over many variants are complex by nature"
93)]
94#![allow(
95    clippy::match_same_arms,
96    reason = "identical match arms are sometimes intentional for documentation and readability"
97)]
98#![allow(
99    clippy::unused_self,
100    reason = "PyO3 methods require &self for Python binding even when Rust impl does not use it"
101)]
102#![allow(
103    clippy::many_single_char_names,
104    reason = "math formulas (Black-Scholes, Greeks) use standard single-character variable names"
105)]
106#![allow(
107    clippy::large_types_passed_by_value,
108    reason = "PyO3 methods require owned values extracted from Python objects"
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
118// Re-exported so `enum_strum_serde!` can reach serde through `$crate`, which works in a consumer
119// that renames its serde dependency or does not depend on it directly.
120#[doc(hidden)]
121pub use serde as __serde;
122
123pub mod accounts;
124pub mod currencies;
125pub mod data;
126pub mod enums;
127pub mod events;
128pub mod fees;
129pub mod identifiers;
130pub mod instruments;
131pub mod macros;
132pub mod orderbook;
133pub mod orders;
134pub mod position;
135pub mod reports;
136pub mod types;
137pub mod venues;
138
139pub(crate) mod expressions;
140
141#[cfg(feature = "ffi")]
142pub mod ffi;
143
144#[cfg(feature = "python")]
145pub mod python;
146
147#[cfg(any(test, feature = "test-support"))]
148pub mod stubs;
149
150#[cfg(feature = "defi")]
151pub mod defi;
152
153mod deserialization;
154
155/// Generates custom-data model behavior.
156pub use nautilus_macros::custom_data;