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#![allow(
51    clippy::manual_let_else,
52    clippy::option_if_let_else,
53    clippy::or_fun_call,
54    clippy::redundant_else,
55    clippy::similar_names,
56    clippy::single_match_else,
57    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
58)]
59#![deny(unsafe_code)]
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::cast_possible_truncation,
67    clippy::cast_possible_wrap,
68    clippy::cast_sign_loss,
69    reason = "venue protocol casts between i64/u64/usize with values bounded by documented OKX ranges"
70)]
71#![allow(
72    clippy::too_many_lines,
73    reason = "venue message parsing and request dispatch functions with large match statements are complex by nature"
74)]
75#![allow(
76    clippy::must_use_candidate,
77    reason = "client accessors and constructors are pervasive; #[must_use] noise is not warranted"
78)]
79#![allow(
80    clippy::trivially_copy_pass_by_ref,
81    reason = "PyO3 methods and trait method signatures require pass-by-reference parity"
82)]
83#![allow(
84    clippy::unsafe_derive_deserialize,
85    reason = "config and message types deserialize plain field values; unsafe in unrelated impls is sound"
86)]
87#![allow(
88    clippy::unused_self,
89    reason = "PyO3 methods and client trait operations take &self for interface parity"
90)]
91#![allow(
92    clippy::match_same_arms,
93    reason = "explicit per-variant arms document venue enum mappings even when bodies coincide"
94)]
95#![allow(
96    clippy::match_wildcard_for_single_variants,
97    reason = "wildcard arms guard against future enum variants in venue message dispatch"
98)]
99#![allow(
100    clippy::assert_is_empty,
101    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
102)]
103// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
104// macro expansion; an item-level `allow` cannot reach the expansion
105#![allow(clippy::clone_on_copy)]
106
107pub mod common;
108pub mod config;
109pub mod data;
110pub mod execution;
111pub mod factories;
112pub mod http;
113pub mod websocket;
114
115mod book;
116
117#[cfg(feature = "python")]
118pub mod python;
119
120// Re-exports
121pub use crate::{
122    common::{
123        enums::{OKXInstrumentType, OKXOrderType, OKXPositionMode, OKXPositionSide, OKXSide},
124        models::OKXInstrument,
125    },
126    data::OKXDataClient,
127    execution::OKXExecutionClient,
128    http::{client::OKXHttpClient, error::OKXHttpError},
129    websocket::{client::OKXWebSocketClient, error::OKXWsError},
130};