nautilus_risk/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//! Risk engine for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-risk` crate provides risk management capabilities including pre-trade
19//! order validation, position sizing calculations, and trading controls. This system ensures
20//! trading operations remain within defined risk parameters and regulatory constraints:
21//!
22//! - **Risk engine**: Central risk management orchestration with configurable trading states.
23//! - **Order validation**: Pre-trade checks for price, quantity, notional limits, and market conditions.
24//! - **Position sizing**: Fixed-risk position sizing calculations with commission and exchange rate support.
25//! - **Trading controls**: Rate limiting, balance validation, and exposure management.
26//! - **Account protection**: Multi-currency balance checks and margin requirement validation.
27//!
28//! # NautilusTrader
29//!
30//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
31//! engine for multi-asset, multi-venue trading systems.
32//!
33//! The system spans research, deterministic simulation, and live execution within a single
34//! event-driven architecture, providing research-to-live semantic parity.
35//!
36//! # Feature Flags
37//!
38//! This crate provides feature flags to control source code inclusion during compilation,
39//! depending on the intended use case, i.e. whether to provide Python bindings
40//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
41//! or as part of a Rust only build.
42//!
43//! - `extension-module`: Builds as a Python extension module.
44//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
45
46#![warn(rustc::all)]
47#![warn(clippy::pedantic)]
48#![allow(
49 clippy::manual_let_else,
50 clippy::option_if_let_else,
51 clippy::or_fun_call,
52 clippy::redundant_else,
53 clippy::similar_names,
54 clippy::single_match_else,
55 reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
56)]
57#![warn(clippy::clone_on_ref_ptr)]
58#![deny(unsafe_code)]
59#![deny(unsafe_op_in_unsafe_fn)]
60#![deny(nonstandard_style)]
61#![deny(missing_debug_implementations)]
62#![deny(clippy::missing_errors_doc)]
63#![deny(clippy::missing_panics_doc)]
64#![deny(rustdoc::broken_intra_doc_links)]
65#![allow(
66 clippy::assert_is_empty,
67 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
68)]
69
70pub mod engine;
71pub mod sizing;
72
73#[cfg(feature = "python")]
74pub mod python;
75
76// Re-exports
77pub use engine::RiskEngine;