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;
22use crate::common::{
23 enums::{OKXContractType, OKXInstrumentStatus, OKXInstrumentType},
24 parse::deserialize_optional_string_to_u64,
25};
26
27/// Represents an instrument on the OKX exchange.
28#[derive(Clone, Debug, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct OKXInstrument {
31 /// Product type (SPOT, MARGIN, SWAP, FUTURES, OPTION).
32 pub inst_type: OKXInstrumentType,
33 /// Instrument ID, e.g. "BTC-USD-SWAP".
34 pub inst_id: Ustr,
35 /// Instrument ID code (numeric). Required for WebSocket order operations.
36 /// E.g., 10458 for BTC-USD-SWAP. May not be present for SPOT instruments.
37 #[serde(default)]
38 pub inst_id_code: Option<u64>,
39 /// Underlying of the instrument, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
40 pub uly: Ustr,
41 /// Instrument family, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
42 pub inst_family: Ustr,
43 /// Base currency, e.g. "BTC" in BTC-USDT. Applicable to SPOT/MARGIN.
44 pub base_ccy: Ustr,
45 /// Quote currency, e.g. "USDT" in BTC-USDT.
46 pub quote_ccy: Ustr,
47 /// Settlement currency, e.g. "BTC" for BTC-USD-SWAP.
48 pub settle_ccy: Ustr,
49 /// Contract value. Only applicable to FUTURES/SWAP/OPTION.
50 pub ct_val: String,
51 /// Contract multiplier. Only applicable to FUTURES/SWAP/OPTION.
52 pub ct_mult: String,
53 /// Contract value currency. Only applicable to FUTURES/SWAP/OPTION.
54 pub ct_val_ccy: String,
55 /// Option type, "C" for call options, "P" for put options. Only applicable to OPTION.
56 pub opt_type: OKXOptionType,
57 /// Strike price. Only applicable to OPTION.
58 pub stk: String,
59 /// Listing time, Unix timestamp format in milliseconds, e.g. "1597026383085".
60 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
61 pub list_time: Option<u64>,
62 /// Expiry time, Unix timestamp format in milliseconds, e.g. "1597026383085".
63 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
64 pub exp_time: Option<u64>,
65 /// Leverage. Not applicable to SPOT.
66 pub lever: String,
67 /// Tick size, e.g. "0.1".
68 pub tick_sz: String,
69 /// Lot size, e.g. "1".
70 pub lot_sz: String,
71 /// Minimum order size.
72 pub min_sz: String,
73 /// Contract type. linear: "linear", inverse: "inverse". Only applicable to FUTURES/SWAP.
74 pub ct_type: OKXContractType,
75 /// Instrument status.
76 pub state: OKXInstrumentStatus,
77 /// Rule type, e.g. "DynamicPL", "CT", etc.
78 pub rule_type: String,
79 /// Maximum limit order size.
80 pub max_lmt_sz: String,
81 /// Maximum market order size.
82 pub max_mkt_sz: String,
83 /// Maximum limit order amount.
84 pub max_lmt_amt: String,
85 /// Maximum market order amount.
86 pub max_mkt_amt: String,
87 /// Maximum TWAP order size.
88 pub max_twap_sz: String,
89 /// Maximum iceberg order size.
90 pub max_iceberg_sz: String,
91 /// Maximum trigger order size.
92 pub max_trigger_sz: String,
93 /// Maximum stop order size.
94 pub max_stop_sz: String,
95}