Skip to main content

nautilus_network/
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//! Network functionality for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-network` crate provides networking components including HTTP, WebSocket, and raw TCP socket
19//! clients, rate limiting, backoff strategies, and socket TLS utilities for connecting to
20//! trading venues and data providers.
21//!
22//! # NautilusTrader
23//!
24//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
25//! engine for multi-asset, multi-venue trading systems.
26//!
27//! The system spans research, deterministic simulation, and live execution within a single
28//! event-driven architecture, providing research-to-live semantic parity.
29//!
30//! # Feature Flags
31//!
32//! This crate provides feature flags to control source code inclusion during compilation,
33//! depending on the intended use case, i.e. whether to provide Python bindings
34//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
35//! or as part of a Rust only build.
36//!
37//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
38//! - `extension-module`: Builds the crate as a Python extension module.
39//! - `turmoil`: Enables deterministic network simulation testing with [turmoil](https://github.com/tokio-rs/turmoil).
40//! - `transport-sockudo`: Adds the [sockudo-ws](https://crates.io/crates/sockudo-ws) WebSocket backend, selectable via `WebSocketConfig.backend`.
41//!
42//! # Testing
43//!
44//! The crate includes both standard integration tests and deterministic network simulation tests using turmoil.
45//!
46//! To run standard tests:
47//! ```bash
48//! cargo nextest run -p nautilus-network
49//! ```
50//!
51//! To run turmoil network simulation tests:
52//! ```bash
53//! cargo nextest run -p nautilus-network --features turmoil
54//! ```
55//!
56//! The turmoil tests simulate various network conditions (reconnections, partitions, etc.) in a deterministic way,
57//! allowing reliable testing of network failure scenarios without flakiness.
58
59#![warn(rustc::all)]
60#![warn(clippy::pedantic)]
61#![deny(unsafe_code)]
62#![deny(unsafe_op_in_unsafe_fn)]
63#![deny(nonstandard_style)]
64#![deny(missing_debug_implementations)]
65#![deny(clippy::missing_errors_doc)]
66#![deny(clippy::missing_panics_doc)]
67#![deny(rustdoc::broken_intra_doc_links)]
68#![allow(
69    clippy::inline_always,
70    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
71)]
72#![allow(
73    clippy::manual_let_else,
74    reason = "match can be clearer than let-else for some patterns"
75)]
76#![allow(
77    clippy::redundant_closure_for_method_calls,
78    reason = "causes clippy ICE on Rust 1.94; matches the workaround in workspace Cargo.toml"
79)]
80#![allow(
81    clippy::cast_possible_truncation,
82    clippy::cast_precision_loss,
83    clippy::cast_sign_loss,
84    reason = "rate limiter and backoff arithmetic requires intentional narrowing casts"
85)]
86#![allow(
87    clippy::too_many_lines,
88    reason = "network client functions with connection management are complex by nature"
89)]
90
91pub mod backoff;
92pub mod dst;
93pub mod http;
94pub mod mode;
95pub mod net;
96pub mod retry;
97pub mod socket;
98pub mod transport;
99pub mod websocket;
100
101mod logging;
102mod tls;
103
104#[cfg(feature = "python")]
105pub mod python;
106
107pub mod error;
108pub mod ratelimiter;
109
110pub use transport::{Message, TransportError};
111
112/// Sentinel message to signal reconnection completion to Rust consumers.
113pub const RECONNECTED: &str = "__RECONNECTED__";