Skip to main content

rust_okx/api/public_data/
responses.rs

1use serde::Deserialize;
2
3use crate::{NumberString, model::InstType};
4
5mod edge;
6
7pub use edge::*;
8
9/// A tradable instrument.
10///
11/// Only commonly used fields are modeled; the struct is `#[non_exhaustive]` and
12/// unknown JSON fields are ignored, so OKX additions are non-breaking.
13#[derive(Debug, Clone, Deserialize)]
14#[serde(rename_all = "camelCase")]
15#[non_exhaustive]
16pub struct Instrument {
17    /// Instrument type.
18    pub inst_type: InstType,
19    /// Instrument ID, e.g. `BTC-USDT`.
20    pub inst_id: String,
21    /// Underlying, e.g. `BTC-USD` (derivatives only).
22    #[serde(default)]
23    pub uly: String,
24    /// Instrument family, e.g. `BTC-USD` (derivatives only).
25    #[serde(default)]
26    pub inst_family: String,
27    /// Base currency, e.g. `BTC` (spot/margin only).
28    #[serde(default)]
29    pub base_ccy: String,
30    /// Quote currency, e.g. `USDT` (spot/margin only).
31    #[serde(default)]
32    pub quote_ccy: String,
33    /// Settlement currency (derivatives only).
34    #[serde(default)]
35    pub settle_ccy: String,
36    /// Lot size (order size increment).
37    #[serde(default)]
38    pub lot_sz: NumberString,
39    /// Tick size (price increment).
40    #[serde(default)]
41    pub tick_sz: NumberString,
42    /// Minimum order size.
43    #[serde(default)]
44    pub min_sz: NumberString,
45    /// Instrument lifecycle state, e.g. `live`, `suspend`.
46    #[serde(default)]
47    pub state: String,
48}
49
50/// OKX system time.
51#[derive(Debug, Clone, Deserialize)]
52#[serde(rename_all = "camelCase")]
53#[non_exhaustive]
54pub struct SystemTime {
55    /// Current OKX system timestamp in Unix milliseconds.
56    pub ts: NumberString,
57}
58
59/// Open interest for an instrument.
60#[derive(Debug, Clone, Deserialize)]
61#[serde(rename_all = "camelCase")]
62#[non_exhaustive]
63pub struct OpenInterest {
64    /// Instrument type.
65    pub inst_type: InstType,
66    /// Instrument ID.
67    pub inst_id: String,
68    /// Open interest in contracts.
69    #[serde(default)]
70    pub oi: NumberString,
71    /// Open interest in coin/currency units.
72    #[serde(default)]
73    pub oi_ccy: NumberString,
74    /// Timestamp (Unix milliseconds).
75    #[serde(default)]
76    pub ts: NumberString,
77}
78
79/// Current funding-rate information.
80#[derive(Debug, Clone, Deserialize)]
81#[serde(rename_all = "camelCase")]
82#[non_exhaustive]
83pub struct FundingRate {
84    /// Instrument type.
85    #[serde(default)]
86    pub inst_type: String,
87    /// Instrument ID.
88    pub inst_id: String,
89    /// Current funding rate.
90    #[serde(default)]
91    pub funding_rate: NumberString,
92    /// Next estimated funding rate.
93    #[serde(default)]
94    pub next_funding_rate: NumberString,
95    /// Funding time (Unix milliseconds).
96    #[serde(default)]
97    pub funding_time: NumberString,
98    /// Next funding time (Unix milliseconds).
99    #[serde(default)]
100    pub next_funding_time: NumberString,
101}
102
103/// Historical funding-rate row.
104#[derive(Debug, Clone, Deserialize)]
105#[serde(rename_all = "camelCase")]
106#[non_exhaustive]
107pub struct FundingRateHistory {
108    /// Instrument ID.
109    pub inst_id: String,
110    /// Funding rate.
111    #[serde(default)]
112    pub funding_rate: NumberString,
113    /// Realized funding rate.
114    #[serde(default)]
115    pub realized_rate: NumberString,
116    /// Funding time (Unix milliseconds).
117    #[serde(default)]
118    pub funding_time: NumberString,
119    /// Funding method.
120    #[serde(default)]
121    pub method: String,
122}
123
124/// Price-limit information for an instrument.
125#[derive(Debug, Clone, Deserialize)]
126#[serde(rename_all = "camelCase")]
127#[non_exhaustive]
128pub struct PriceLimit {
129    /// Instrument ID.
130    pub inst_id: String,
131    /// Highest buy price.
132    #[serde(default)]
133    pub buy_lmt: NumberString,
134    /// Lowest sell price.
135    #[serde(default)]
136    pub sell_lmt: NumberString,
137    /// Timestamp (Unix milliseconds).
138    #[serde(default)]
139    pub ts: NumberString,
140}
141
142/// Mark-price information.
143#[derive(Debug, Clone, Deserialize)]
144#[serde(rename_all = "camelCase")]
145#[non_exhaustive]
146pub struct MarkPrice {
147    /// Instrument type.
148    pub inst_type: InstType,
149    /// Instrument ID.
150    pub inst_id: String,
151    /// Mark price.
152    #[serde(default)]
153    pub mark_px: NumberString,
154    /// Timestamp (Unix milliseconds).
155    #[serde(default)]
156    pub ts: NumberString,
157}
158
159/// Delivery/exercise history row.
160#[derive(Debug, Clone, Deserialize)]
161#[serde(rename_all = "camelCase")]
162#[non_exhaustive]
163pub struct DeliveryExercise {
164    /// Instrument type.
165    #[serde(default)]
166    pub inst_type: String,
167    /// Instrument ID.
168    #[serde(default)]
169    pub inst_id: String,
170    /// Delivery/exercise price.
171    #[serde(default)]
172    pub px: NumberString,
173    /// Delivery/exercise type.
174    #[serde(rename = "type", default)]
175    pub exercise_type: String,
176    /// Timestamp (Unix milliseconds).
177    #[serde(default)]
178    pub ts: NumberString,
179}
180
181/// Public position-tier information.
182#[derive(Debug, Clone, Deserialize)]
183#[serde(rename_all = "camelCase")]
184#[non_exhaustive]
185pub struct PositionTier {
186    /// Instrument type.
187    pub inst_type: InstType,
188    /// Trade mode.
189    #[serde(default)]
190    pub td_mode: String,
191    /// Instrument ID.
192    #[serde(default)]
193    pub inst_id: String,
194    /// Tier.
195    #[serde(default)]
196    pub tier: String,
197    /// Minimum size.
198    #[serde(default)]
199    pub min_sz: NumberString,
200    /// Maximum size.
201    #[serde(default)]
202    pub max_sz: NumberString,
203    /// Initial margin rate.
204    #[serde(default)]
205    pub imr: NumberString,
206    /// Maintenance margin rate.
207    #[serde(default)]
208    pub mmr: NumberString,
209}
210
211/// Insurance-fund snapshot.
212#[derive(Debug, Clone, Deserialize)]
213#[serde(rename_all = "camelCase")]
214#[non_exhaustive]
215pub struct InsuranceFund {
216    /// Instrument type.
217    #[serde(default)]
218    pub inst_type: String,
219    /// Fund type.
220    #[serde(rename = "type", default)]
221    pub fund_type: String,
222    /// Currency.
223    #[serde(default)]
224    pub ccy: String,
225    /// Balance amount.
226    #[serde(default)]
227    pub amt: NumberString,
228    /// Timestamp (Unix milliseconds).
229    #[serde(default)]
230    pub ts: NumberString,
231}
232
233/// Contract/coin conversion result.
234#[derive(Debug, Clone, Deserialize)]
235#[serde(rename_all = "camelCase")]
236#[non_exhaustive]
237pub struct ConvertContractCoin {
238    /// Instrument ID.
239    #[serde(default)]
240    pub inst_id: String,
241    /// Converted size.
242    #[serde(default)]
243    pub sz: NumberString,
244    /// Conversion price.
245    #[serde(default)]
246    pub px: NumberString,
247    /// Conversion unit.
248    #[serde(default)]
249    pub unit: String,
250}