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