nautilus_okx/common/models.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 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 /// Underlying of the instrument, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
36 pub uly: Ustr,
37 /// Instrument family, e.g. "BTC-USD". Only applicable to FUTURES/SWAP/OPTION.
38 pub inst_family: Ustr,
39 /// Base currency, e.g. "BTC" in BTC-USDT. Applicable to SPOT/MARGIN.
40 pub base_ccy: Ustr,
41 /// Quote currency, e.g. "USDT" in BTC-USDT.
42 pub quote_ccy: Ustr,
43 /// Settlement currency, e.g. "BTC" for BTC-USD-SWAP.
44 pub settle_ccy: Ustr,
45 /// Contract value. Only applicable to FUTURES/SWAP/OPTION.
46 pub ct_val: String,
47 /// Contract multiplier. Only applicable to FUTURES/SWAP/OPTION.
48 pub ct_mult: String,
49 /// Contract value currency. Only applicable to FUTURES/SWAP/OPTION.
50 pub ct_val_ccy: String,
51 /// Option type, "C" for call options, "P" for put options. Only applicable to OPTION.
52 pub opt_type: OKXOptionType,
53 /// Strike price. Only applicable to OPTION.
54 pub stk: String,
55 /// Listing time, Unix timestamp format in milliseconds, e.g. "1597026383085".
56 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
57 pub list_time: Option<u64>,
58 /// Expiry time, Unix timestamp format in milliseconds, e.g. "1597026383085".
59 #[serde(deserialize_with = "deserialize_optional_string_to_u64")]
60 pub exp_time: Option<u64>,
61 /// Leverage. Not applicable to SPOT.
62 pub lever: String,
63 /// Tick size, e.g. "0.1".
64 pub tick_sz: String,
65 /// Lot size, e.g. "1".
66 pub lot_sz: String,
67 /// Minimum order size.
68 pub min_sz: String,
69 /// Contract type. linear: "linear", inverse: "inverse". Only applicable to FUTURES/SWAP.
70 pub ct_type: OKXContractType,
71 /// Instrument status.
72 pub state: OKXInstrumentStatus,
73 /// Rule type, e.g. "DynamicPL", "CT", etc.
74 pub rule_type: String,
75 /// Maximum limit order size.
76 pub max_lmt_sz: String,
77 /// Maximum market order size.
78 pub max_mkt_sz: String,
79 /// Maximum limit order amount.
80 pub max_lmt_amt: String,
81 /// Maximum market order amount.
82 pub max_mkt_amt: String,
83 /// Maximum TWAP order size.
84 pub max_twap_sz: String,
85 /// Maximum iceberg order size.
86 pub max_iceberg_sz: String,
87 /// Maximum trigger order size.
88 pub max_trigger_sz: String,
89 /// Maximum stop order size.
90 pub max_stop_sz: String,
91}