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//! - `ffi`: Enables the C foreign function interface (FFI) from [cbindgen](https://github.com/mozilla/cbindgen).
37//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
38//! - `stubs`: Enables type stubs for use in testing scenarios.
39//! - `high-precision`: Enables [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode) to use 128-bit value types.
40//! - `defi`: Enables the DeFi (Decentralized Finance) domain model.
41//! - `extension-module`: Builds the crate as a Python extension module.
42
43#![warn(rustc::all)]
44#![warn(clippy::pedantic)]
45#![deny(unsafe_code)]
46#![deny(unsafe_op_in_unsafe_fn)]
47#![deny(nonstandard_style)]
48#![deny(missing_debug_implementations)]
49#![deny(clippy::missing_errors_doc)]
50#![deny(clippy::missing_panics_doc)]
51#![deny(rustdoc::broken_intra_doc_links)]
52#![cfg_attr(test, allow(clippy::large_stack_arrays))]
53#![allow(
54    clippy::inline_always,
55    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
56)]
57#![allow(
58    clippy::manual_let_else,
59    reason = "match can be clearer than let-else for some patterns"
60)]
61#![allow(
62    clippy::redundant_closure_for_method_calls,
63    reason = "causes clippy ICE on Rust 1.94; matches the workaround in workspace Cargo.toml"
64)]
65#![allow(
66    clippy::float_cmp,
67    reason = "numeric domain crate: float equality comparisons are pervasive and intentional"
68)]
69#![allow(
70    clippy::unsafe_derive_deserialize,
71    reason = "serde derives on types with unsafe methods for FFI are intentional"
72)]
73#![allow(
74    clippy::cast_possible_truncation,
75    clippy::cast_possible_wrap,
76    clippy::cast_sign_loss,
77    clippy::cast_precision_loss,
78    reason = "numeric domain crate: casts are fundamental to fixed-point arithmetic and type conversions"
79)]
80#![allow(
81    clippy::trivially_copy_pass_by_ref,
82    reason = "changing pass-by-ref to pass-by-value would break FFI and Python binding signatures"
83)]
84#![allow(
85    clippy::similar_names,
86    reason = "domain terminology creates naturally similar names (bid/ask, base/quote)"
87)]
88#![allow(
89    clippy::too_many_lines,
90    reason = "trading domain functions with match arms over many variants are complex by nature"
91)]
92#![allow(
93    clippy::match_same_arms,
94    reason = "identical match arms are sometimes intentional for documentation and readability"
95)]
96#![allow(
97    clippy::unused_self,
98    reason = "PyO3 methods require &self for Python binding even when Rust impl does not use it"
99)]
100#![allow(
101    clippy::many_single_char_names,
102    reason = "math formulas (Black-Scholes, Greeks) use standard single-character variable names"
103)]
104#![allow(
105    clippy::large_types_passed_by_value,
106    reason = "PyO3 methods require owned values extracted from Python objects"
107)]
108
109pub mod accounts;
110pub mod currencies;
111pub mod data;
112pub mod enums;
113pub mod events;
114pub mod identifiers;
115pub mod instruments;
116pub mod macros;
117pub mod orderbook;
118pub mod orders;
119pub mod position;
120pub mod reports;
121pub mod types;
122pub mod venues;
123
124pub(crate) mod expressions;
125
126#[cfg(feature = "ffi")]
127pub mod ffi;
128
129#[cfg(feature = "python")]
130pub mod python;
131
132#[cfg(any(test, feature = "stubs"))]
133pub mod stubs;
134
135#[cfg(feature = "defi")]
136pub mod defi;