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 clients and connection policy for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The crate provides asynchronous HTTP, reconnecting WebSocket, and suffix-framed TCP clients,
19//! together with rate limiting, retry, backoff, proxy, and TLS support.
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//! - `python`: Exposes the `TransportBackend` enum through [PyO3](https://pyo3.rs).
32//! - `extension-module`: Builds the crate as a Python extension module.
33//! - `turmoil`: Enables deterministic network simulation testing with
34//!   [turmoil](https://github.com/tokio-rs/turmoil).
35//! - `transport-sockudo`: Adds the [sockudo-ws](https://crates.io/crates/sockudo-ws)
36//!   WebSocket backend, selectable through `WebSocketConfig.backend`. This feature is enabled by
37//!   default; use `default-features = false` to omit the dependency.
38//!
39//! # Testing
40//!
41//! The crate includes standard integration tests and deterministic failure-path tests using
42//! `turmoil`.
43//!
44//! To run standard tests:
45//! ```bash
46//! cargo nextest run -p nautilus-network
47//! ```
48//!
49//! To run turmoil network simulation tests:
50//! ```bash
51//! cargo nextest run -p nautilus-network --features turmoil
52//! ```
53//!
54//! The `turmoil` tests cover reconnections, partitions, and related network failures without
55//! relying on wall-clock timing.
56
57#![warn(rustc::all)]
58#![warn(clippy::pedantic)]
59#![deny(unsafe_code)]
60#![deny(unsafe_op_in_unsafe_fn)]
61#![deny(nonstandard_style)]
62#![deny(missing_debug_implementations)]
63#![deny(clippy::missing_errors_doc)]
64#![deny(clippy::missing_panics_doc)]
65#![deny(rustdoc::broken_intra_doc_links)]
66#![allow(
67    clippy::inline_always,
68    reason = "hot-path functions use #[inline(always)] intentionally for constant-folding"
69)]
70#![allow(
71    clippy::manual_let_else,
72    reason = "match can be clearer than let-else for some patterns"
73)]
74#![allow(
75    clippy::cast_possible_truncation,
76    clippy::cast_precision_loss,
77    clippy::cast_sign_loss,
78    reason = "rate limiter and backoff arithmetic requires intentional narrowing casts"
79)]
80#![allow(
81    clippy::too_many_lines,
82    reason = "network client functions with connection management are complex by nature"
83)]
84#![allow(
85    clippy::assert_is_empty,
86    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
87)]
88// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
89// macro expansion; an item-level `allow` cannot reach the expansion
90#![allow(clippy::clone_on_copy)]
91
92pub mod backoff;
93pub mod dst;
94pub mod http;
95pub mod mode;
96pub mod net;
97pub mod retry;
98pub mod socket;
99pub mod transport;
100pub mod websocket;
101
102mod heartbeat;
103mod logging;
104mod sink;
105mod tls;
106
107#[cfg(feature = "python")]
108pub mod python;
109
110pub mod error;
111pub mod ratelimiter;
112
113pub use sink::{SocketState, SocketStateSink};
114pub use transport::{Message, TransportError};
115
116/// Sentinel message indicating that a WebSocket reconnection completed.
117pub const RECONNECTED: &str = "__RECONNECTED__";