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 instrument loading, live market data, and order execution through
19//! the **OKX v5 API**. It includes typed HTTP and WebSocket clients and live-node factories for spot,
20//! derivatives, spreads, and event contracts.
21//!
22//! All public links inside this crate reference the English version.
23//!
24//! The official OKX API reference can be found at <https://www.okx.com/docs-v5/en/>.
25//!
26//! # NautilusTrader
27//!
28//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native trading engine
29//! with a deterministic, event-driven architecture for multi-asset, multi-venue systems.
30//!
31//! The system spans research, simulation, and live execution, providing research-to-live semantic parity.
32//!
33//! # Feature Flags
34//!
35//! Feature flags control code inclusion for Rust builds and Python bindings:
36//!
37//! - `examples`: Enables the crate's example binaries.
38//! - `extension-module`: Builds as a Python extension module.
39//! - `high-precision` (default): Enables
40//!   [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation/#precision-mode)
41//!   to use 128-bit value types.
42//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
43//! - `simulation`: Enables deterministic simulation testing with
44//!   [MadSim](https://crates.io/crates/madsim).
45//!
46//! # Integrator Attribution
47//!
48//! HTTP and WebSocket order submissions set `tag` to NautilusTrader's fixed integration ID.
49//! Caller-provided tags are replaced.
50//!
51//! # Documentation
52//!
53//! - [Integration guide](https://nautilustrader.io/docs/nightly/integrations/okx/)
54//! - [Rust examples](https://github.com/nautechsystems/nautilus_trader/tree/develop/crates/adapters/okx/examples)
55//! - [Python examples](https://github.com/nautechsystems/nautilus_trader/tree/develop/examples/live/okx)
56
57#![warn(rustc::all)]
58#![warn(clippy::pedantic)]
59#![allow(
60    clippy::manual_let_else,
61    clippy::option_if_let_else,
62    clippy::or_fun_call,
63    clippy::redundant_else,
64    clippy::similar_names,
65    clippy::single_match_else,
66    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
67)]
68#![deny(unsafe_code)]
69#![deny(nonstandard_style)]
70#![deny(missing_debug_implementations)]
71#![deny(clippy::missing_errors_doc)]
72#![deny(clippy::missing_panics_doc)]
73#![deny(rustdoc::broken_intra_doc_links)]
74#![allow(
75    clippy::cast_possible_truncation,
76    clippy::cast_possible_wrap,
77    clippy::cast_sign_loss,
78    reason = "venue protocol casts between i64/u64/usize with values bounded by documented OKX ranges"
79)]
80#![allow(
81    clippy::too_many_lines,
82    reason = "venue message parsing and request dispatch functions with large match statements are complex by nature"
83)]
84#![allow(
85    clippy::must_use_candidate,
86    reason = "client accessors and constructors are pervasive; #[must_use] noise is not warranted"
87)]
88#![allow(
89    clippy::trivially_copy_pass_by_ref,
90    reason = "PyO3 methods and trait method signatures require pass-by-reference parity"
91)]
92#![allow(
93    clippy::unsafe_derive_deserialize,
94    reason = "config and message types deserialize plain field values; unsafe in unrelated impls is sound"
95)]
96#![allow(
97    clippy::unused_self,
98    reason = "PyO3 methods and client trait operations take &self for interface parity"
99)]
100#![allow(
101    clippy::match_same_arms,
102    reason = "explicit per-variant arms document venue enum mappings even when bodies coincide"
103)]
104#![allow(
105    clippy::match_wildcard_for_single_variants,
106    reason = "wildcard arms guard against future enum variants in venue message dispatch"
107)]
108#![allow(
109    clippy::assert_is_empty,
110    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
111)]
112// pyo3's `from_py_object` generates `.clone()` on `Copy` fields that clippy flags from the
113// macro expansion; an item-level `allow` cannot reach the expansion
114#![allow(clippy::clone_on_copy)]
115
116pub mod common;
117pub mod config;
118pub mod data;
119pub mod execution;
120pub mod factories;
121pub mod http;
122pub mod websocket;
123
124mod book;
125
126#[cfg(feature = "python")]
127pub mod python;
128
129// Re-exports
130pub use crate::{
131    common::{
132        enums::{OKXInstrumentType, OKXOrderType, OKXPositionMode, OKXPositionSide, OKXSide},
133        models::OKXInstrument,
134    },
135    data::OKXDataClient,
136    execution::OKXExecutionClient,
137    http::{client::OKXHttpClient, error::OKXHttpError},
138    websocket::{client::OKXWebSocketClient, error::OKXWsError},
139};