Skip to main content

nautilus_okx/
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//! [NautilusTrader](https://nautilustrader.io) adapter for the [OKX](https://www.okx.com) cryptocurrency exchange.
17//!
18//! The `nautilus-okx` crate provides client bindings (HTTP & WebSocket) and data
19//! models for the official **OKX v5 API**.
20//!
21//! The official OKX API reference can be found at <https://www.okx.com/docs-v5/en/>.
22//! All public links inside this crate reference the English version.
23//!
24//! # NautilusTrader
25//!
26//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
27//! engine for multi-asset, multi-venue trading systems.
28//!
29//! The system spans research, deterministic simulation, and live execution within a single
30//! event-driven architecture, providing research-to-live semantic parity.
31//!
32//! # Feature Flags
33//!
34//! This crate provides feature flags to control source code inclusion during compilation,
35//! depending on the intended use case, i.e. whether to provide Python bindings
36//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
37//! or as part of a Rust only build.
38//!
39//! - `examples`: Enables the crate's example binaries.
40//! - `extension-module`: Builds as a Python extension module.
41//! - `high-precision` (default): Enables
42//!   [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation/#precision-mode)
43//!   to use 128-bit value types.
44//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
45//! - `simulation`: Enables deterministic simulation testing with
46//!   [MadSim](https://crates.io/crates/madsim).
47
48#![warn(rustc::all)]
49#![warn(clippy::pedantic)]
50#![deny(unsafe_code)]
51#![deny(nonstandard_style)]
52#![deny(missing_debug_implementations)]
53#![deny(clippy::missing_errors_doc)]
54#![deny(clippy::missing_panics_doc)]
55#![deny(rustdoc::broken_intra_doc_links)]
56#![allow(
57    clippy::similar_names,
58    reason = "venue and domain terms such as inst/inst_id and bid/ask are intentionally parallel"
59)]
60#![allow(
61    clippy::cast_possible_truncation,
62    clippy::cast_possible_wrap,
63    clippy::cast_sign_loss,
64    reason = "venue protocol casts between i64/u64/usize with values bounded by documented OKX ranges"
65)]
66#![allow(
67    clippy::too_many_lines,
68    reason = "venue message parsing and request dispatch functions with large match statements are complex by nature"
69)]
70#![allow(
71    clippy::must_use_candidate,
72    reason = "client accessors and constructors are pervasive; #[must_use] noise is not warranted"
73)]
74#![allow(
75    clippy::trivially_copy_pass_by_ref,
76    reason = "PyO3 methods and trait method signatures require pass-by-reference parity"
77)]
78#![allow(
79    clippy::unsafe_derive_deserialize,
80    reason = "config and message types deserialize plain field values; unsafe in unrelated impls is sound"
81)]
82#![allow(
83    clippy::unused_self,
84    reason = "PyO3 methods and client trait operations take &self for interface parity"
85)]
86#![allow(
87    clippy::match_same_arms,
88    reason = "explicit per-variant arms document venue enum mappings even when bodies coincide"
89)]
90#![allow(
91    clippy::match_wildcard_for_single_variants,
92    reason = "wildcard arms guard against future enum variants in venue message dispatch"
93)]
94#![allow(
95    clippy::manual_let_else,
96    reason = "match can be clearer than let-else for some patterns"
97)]
98#![allow(
99    clippy::single_match_else,
100    reason = "match can be clearer than if-let-else for some patterns"
101)]
102#![allow(
103    clippy::redundant_else,
104    reason = "sometimes explicit else blocks improve readability"
105)]
106// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
107// macro expansion; an item-level `allow` cannot reach the expansion
108#![allow(clippy::clone_on_copy)]
109
110pub mod common;
111pub mod config;
112pub mod data;
113pub mod execution;
114pub mod factories;
115pub mod http;
116pub mod websocket;
117
118mod book;
119
120#[cfg(feature = "python")]
121pub mod python;
122
123// Re-exports
124pub use crate::{
125    common::{
126        enums::{OKXInstrumentType, OKXOrderType, OKXPositionMode, OKXPositionSide, OKXSide},
127        models::OKXInstrument,
128    },
129    data::OKXDataClient,
130    execution::OKXExecutionClient,
131    http::{client::OKXHttpClient, error::OKXHttpError},
132    websocket::{client::OKXWebSocketClient, error::OKXWsError},
133};