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//! - `test-support`: Enables test fixtures, builders, specs, and defaults.
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::float_cmp,
65 reason = "numeric domain crate: float equality comparisons are pervasive and intentional"
66)]
67#![allow(
68 clippy::unsafe_derive_deserialize,
69 reason = "serde derives on types with unsafe methods for FFI are intentional"
70)]
71#![allow(
72 clippy::cast_possible_truncation,
73 clippy::cast_possible_wrap,
74 clippy::cast_sign_loss,
75 clippy::cast_precision_loss,
76 reason = "numeric domain crate: casts are fundamental to fixed-point arithmetic and type conversions"
77)]
78#![allow(
79 clippy::trivially_copy_pass_by_ref,
80 reason = "changing pass-by-ref to pass-by-value would break FFI and Python binding signatures"
81)]
82#![allow(
83 clippy::similar_names,
84 reason = "domain terminology creates naturally similar names (bid/ask, base/quote)"
85)]
86#![allow(
87 clippy::too_many_lines,
88 reason = "trading domain functions with match arms over many variants are complex by nature"
89)]
90#![allow(
91 clippy::match_same_arms,
92 reason = "identical match arms are sometimes intentional for documentation and readability"
93)]
94#![allow(
95 clippy::unused_self,
96 reason = "PyO3 methods require &self for Python binding even when Rust impl does not use it"
97)]
98#![allow(
99 clippy::many_single_char_names,
100 reason = "math formulas (Black-Scholes, Greeks) use standard single-character variable names"
101)]
102#![allow(
103 clippy::large_types_passed_by_value,
104 reason = "PyO3 methods require owned values extracted from Python objects"
105)]
106#![allow(
107 clippy::assert_is_empty,
108 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
109)]
110// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
111// macro expansion; an item-level `allow` cannot reach the expansion
112#![allow(clippy::clone_on_copy)]
113
114pub mod accounts;
115pub mod currencies;
116pub mod data;
117pub mod enums;
118pub mod events;
119pub mod identifiers;
120pub mod instruments;
121pub mod macros;
122pub mod orderbook;
123pub mod orders;
124pub mod position;
125pub mod reports;
126pub mod types;
127pub mod venues;
128
129pub(crate) mod expressions;
130
131#[cfg(feature = "ffi")]
132pub mod ffi;
133
134#[cfg(feature = "python")]
135pub mod python;
136
137#[cfg(any(test, feature = "test-support"))]
138pub mod stubs;
139
140#[cfg(feature = "defi")]
141pub mod defi;