nautilus_serialization/
lib.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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//! Data serialization and format conversion for [NautilusTrader](http://nautilustrader.io).
17//!
18//! The `nautilus-serialization` crate provides comprehensive data serialization capabilities for converting
19//! trading data between different formats including Apache Arrow and Cap'n Proto.
20//! This enables efficient data storage, retrieval, and interoperability across different systems:
21//!
22//! - **Apache Arrow integration**: Schema definitions and encoding/decoding for market data types.
23//! - **Parquet file operations**: High-performance columnar storage for historical data analysis.
24//! - **Record batch processing**: Efficient batch operations for time-series data.
25//! - **Schema management**: Type-safe schema definitions with metadata preservation.
26//! - **Cross-format conversion**: Seamless data interchange between Arrow, Cap'n Proto, and native types.
27//! - **Cap'n Proto serialization**: Zero-copy, schema-based serialization for efficient data interchange (requires `capnp` feature).
28//!
29//! # Platform
30//!
31//! [NautilusTrader](http://nautilustrader.io) is an open-source, high-performance, production-grade
32//! algorithmic trading platform, providing quantitative traders with the ability to backtest
33//! portfolios of automated trading strategies on historical data with an event-driven engine,
34//! and also deploy those same strategies live, with no code changes.
35//!
36//! NautilusTrader's design, architecture, and implementation philosophy prioritizes software correctness and safety at the
37//! highest level, with the aim of supporting mission-critical, trading system backtesting and live deployment workloads.
38//!
39//! # Feature flags
40//!
41//! This crate provides feature flags to control source code inclusion during compilation,
42//! depending on the intended use case, i.e. whether to provide Python bindings
43//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
44//! or as part of a Rust only build.
45//!
46//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
47//! - `high-precision`: Enables [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode) to use 128-bit value types.
48//! - `extension-module`: Builds the crate as a Python extension module.
49//! - `capnp`: Enables [Cap'n Proto](https://capnproto.org/) serialization support.
50
51#![warn(rustc::all)]
52#![deny(unsafe_code)]
53#![deny(nonstandard_style)]
54#![deny(missing_debug_implementations)]
55#![deny(clippy::missing_errors_doc)]
56#![deny(clippy::missing_panics_doc)]
57#![deny(rustdoc::broken_intra_doc_links)]
58
59pub mod arrow;
60
61/// Re-export MsgPack serialization helpers for consumers expecting to configure codecs via this crate.
62pub use nautilus_core::serialization::msgpack;
63
64#[cfg(feature = "capnp")]
65pub mod capnp;
66
67#[cfg(feature = "capnp")]
68macro_rules! include_capnp_module {
69    ($name:ident, $path:expr) => {
70        #[cfg(all(feature = "capnp", not(docs_rs)))]
71        #[allow(clippy::all, warnings, dead_code, missing_debug_implementations)]
72        pub mod $name {
73            include!(concat!(env!("OUT_DIR"), $path));
74        }
75
76        #[cfg(all(feature = "capnp", docs_rs))]
77        #[allow(clippy::all, warnings, dead_code, missing_debug_implementations)]
78        pub mod $name {
79            include!(concat!(
80                env!("CARGO_MANIFEST_DIR"),
81                "/generated/capnp",
82                $path
83            ));
84        }
85    };
86}
87
88#[cfg(feature = "capnp")]
89include_capnp_module!(base_capnp, "/common/base_capnp.rs");
90#[cfg(feature = "capnp")]
91include_capnp_module!(identifiers_capnp, "/common/identifiers_capnp.rs");
92#[cfg(feature = "capnp")]
93include_capnp_module!(types_capnp, "/common/types_capnp.rs");
94#[cfg(feature = "capnp")]
95include_capnp_module!(enums_capnp, "/common/enums_capnp.rs");
96#[cfg(feature = "capnp")]
97include_capnp_module!(trading_capnp, "/commands/trading_capnp.rs");
98#[cfg(feature = "capnp")]
99include_capnp_module!(data_capnp, "/commands/data_capnp.rs");
100#[cfg(feature = "capnp")]
101include_capnp_module!(order_capnp, "/events/order_capnp.rs");
102#[cfg(feature = "capnp")]
103include_capnp_module!(position_capnp, "/events/position_capnp.rs");
104#[cfg(feature = "capnp")]
105include_capnp_module!(account_capnp, "/events/account_capnp.rs");
106#[cfg(feature = "capnp")]
107include_capnp_module!(market_capnp, "/data/market_capnp.rs");
108
109#[cfg(feature = "python")]
110pub mod python;