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//! - `arrow`: Enables Apache Arrow schema and `RecordBatch` registries for custom data.
39//! - `python-arrow`: Enables Python bindings together with `PyArrow` `RecordBatch` bridging.
40//! - `stubs`: Enables type stubs for use in testing scenarios.
41//! - `high-precision`: Enables [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode) to use 128-bit value types.
42//! - `defi`: Enables the DeFi (Decentralized Finance) domain model.
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#![cfg_attr(test, allow(clippy::large_stack_arrays))]
55#![allow(
56    clippy::inline_always,
57    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
58)]
59#![allow(
60    clippy::manual_let_else,
61    reason = "match can be clearer than let-else for some patterns"
62)]
63#![allow(
64    clippy::redundant_closure_for_method_calls,
65    reason = "causes clippy ICE on Rust 1.94; matches the workaround in workspace Cargo.toml"
66)]
67#![allow(
68    clippy::float_cmp,
69    reason = "numeric domain crate: float equality comparisons are pervasive and intentional"
70)]
71#![allow(
72    clippy::unsafe_derive_deserialize,
73    reason = "serde derives on types with unsafe methods for FFI are intentional"
74)]
75#![allow(
76    clippy::cast_possible_truncation,
77    clippy::cast_possible_wrap,
78    clippy::cast_sign_loss,
79    clippy::cast_precision_loss,
80    reason = "numeric domain crate: casts are fundamental to fixed-point arithmetic and type conversions"
81)]
82#![allow(
83    clippy::trivially_copy_pass_by_ref,
84    reason = "changing pass-by-ref to pass-by-value would break FFI and Python binding signatures"
85)]
86#![allow(
87    clippy::similar_names,
88    reason = "domain terminology creates naturally similar names (bid/ask, base/quote)"
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
111pub mod accounts;
112pub mod currencies;
113pub mod data;
114pub mod enums;
115pub mod events;
116pub mod identifiers;
117pub mod instruments;
118pub mod macros;
119pub mod orderbook;
120pub mod orders;
121pub mod position;
122pub mod reports;
123pub mod types;
124pub mod venues;
125
126pub(crate) mod expressions;
127
128#[cfg(feature = "ffi")]
129pub mod ffi;
130
131#[cfg(feature = "python")]
132pub mod python;
133
134#[cfg(any(test, feature = "stubs"))]
135pub mod stubs;
136
137#[cfg(feature = "defi")]
138pub mod defi;