nautilus_okx/common/models.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//! Data models representing OKX API payloads consumed by the adapter.
17
18use serde::{Deserialize, Serialize};
19use ustr::Ustr;
20
21use super::enums::{OKXOptionType, OKXTriggerType};
22use crate::common::{
23 enums::{OKXContractType, OKXInstrumentStatus, OKXInstrumentType},
24 parse::deserialize_optional_string_to_u64,
25};
26
27/// Attached TP/SL child order metadata returned by OKX on parent orders.
28#[derive(Clone, Debug, Default, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct OKXAttachedAlgoOrd {
31 /// Attached algo order ID, if assigned by OKX.
32 #[serde(default)]
33 pub attach_algo_id: String,
34 /// Attached child client order ID.
35 #[serde(default)]
36 pub attach_algo_cl_ord_id: String,
37 /// Stop-loss trigger price.
38 #[serde(default)]
39 pub sl_trigger_px: String,
40 /// Stop-loss order price.
41 #[serde(default)]
42 pub sl_ord_px: String,
43 /// Stop-loss trigger price type.
44 #[serde(default)]
45 pub sl_trigger_px_type: Option<OKXTriggerType>,
46 /// Take-profit trigger price.
47 #[serde(default)]
48 pub tp_trigger_px: String,
49 /// Take-profit order price.
50 #[serde(default)]
51 pub tp_ord_px: String,
52 /// Take-profit trigger price type.
53 #[serde(default)]
54 pub tp_trigger_px_type: Option<OKXTriggerType>,
55}
56
57/// Represents an instrument on the OKX exchange.
58#[derive(Clone, Debug, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct OKXInstrument {
61 /// Product type (SPOT, MARGIN, SWAP, FUTURES, OPTION).
62 pub inst_type: OKXInstrumentType,
63 /// Instrument ID, e.g. "BTC-USD-SWAP".
64 pub inst_id: Ustr,
65 /// Instrument ID code (numeric). Required for WebSocket order operations.
66 /// E.g., 10458 for BTC-USD-SWAP.
67 #[serde(default)]
68 pub inst_id_code: Option<u64>,
69 /// Underlying of the instrument, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
70 pub uly: Ustr,
71 /// Instrument family, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
72 pub inst_family: Ustr,
73 /// Base currency, e.g. "BTC" in BTC-USDT. Applicable to SPOT/MARGIN.
74 pub base_ccy: Ustr,
75 /// Quote currency, e.g. "USDT" in BTC-USDT.
76 pub quote_ccy: Ustr,
77 /// Settlement currency, e.g. "BTC" for BTC-USD-SWAP.
78 pub settle_ccy: Ustr,
79 /// Contract value. Only applicable to FUTURES/SWAP/OPTION.
80 pub ct_val: String,
81 /// Contract multiplier. Only applicable to FUTURES/SWAP/OPTION.
82 pub ct_mult: String,
83 /// Contract value currency. Only applicable to FUTURES/SWAP/OPTION.
84 pub ct_val_ccy: String,
85 /// Option type, "C" for call options, "P" for put options. Only applicable to OPTION.
86 pub opt_type: OKXOptionType,
87 /// Strike price. Only applicable to OPTION.
88 pub stk: String,
89 /// Listing time, Unix timestamp format in milliseconds, e.g. "1597026383085".
90 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
91 pub list_time: Option<u64>,
92 /// Expiry time, Unix timestamp format in milliseconds, e.g. "1597026383085".
93 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
94 pub exp_time: Option<u64>,
95 /// Leverage. Not applicable to SPOT.
96 pub lever: String,
97 /// Tick size, e.g. "0.1".
98 pub tick_sz: String,
99 /// Lot size, e.g. "1".
100 pub lot_sz: String,
101 /// Minimum order size.
102 pub min_sz: String,
103 /// Contract type. linear: "linear", inverse: "inverse". Only applicable to FUTURES/SWAP.
104 pub ct_type: OKXContractType,
105 /// Instrument status.
106 pub state: OKXInstrumentStatus,
107 /// Rule type, e.g. "DynamicPL", "CT", etc.
108 pub rule_type: String,
109 /// Maximum limit order size.
110 #[serde(default)]
111 pub max_lmt_sz: String,
112 /// Maximum market order size.
113 #[serde(default)]
114 pub max_mkt_sz: String,
115 /// Maximum limit order amount.
116 #[serde(default)]
117 pub max_lmt_amt: String,
118 /// Maximum market order amount.
119 #[serde(default)]
120 pub max_mkt_amt: String,
121 /// Maximum TWAP order size.
122 #[serde(default)]
123 pub max_twap_sz: String,
124 /// Maximum iceberg order size.
125 #[serde(default)]
126 pub max_iceberg_sz: String,
127 /// Maximum trigger order size.
128 #[serde(default)]
129 pub max_trigger_sz: String,
130 /// Maximum stop order size.
131 #[serde(default)]
132 pub max_stop_sz: String,
133}