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    /// Open interest in USD.
75    #[serde(default)]
76    pub oi_usd: NumberString,
77    /// Timestamp (Unix milliseconds).
78    #[serde(default)]
79    pub ts: NumberString,
80}
81
82/// Current funding-rate information.
83#[derive(Debug, Clone, Deserialize)]
84#[serde(rename_all = "camelCase")]
85#[non_exhaustive]
86pub struct FundingRate {
87    /// Instrument type.
88    #[serde(default)]
89    pub inst_type: String,
90    /// Instrument ID.
91    pub inst_id: String,
92    /// Current funding rate.
93    #[serde(default)]
94    pub funding_rate: NumberString,
95    /// Next estimated funding rate.
96    #[serde(default)]
97    pub next_funding_rate: NumberString,
98    /// Funding time (Unix milliseconds).
99    #[serde(default)]
100    pub funding_time: NumberString,
101    /// Next funding time (Unix milliseconds).
102    #[serde(default)]
103    pub next_funding_time: NumberString,
104}
105
106/// Historical funding-rate row.
107#[derive(Debug, Clone, Deserialize)]
108#[serde(rename_all = "camelCase")]
109#[non_exhaustive]
110pub struct FundingRateHistory {
111    /// Instrument ID.
112    pub inst_id: String,
113    /// Instrument type.
114    #[serde(default)]
115    pub inst_type: String,
116    /// Funding rate formula type.
117    #[serde(default)]
118    pub formula_type: String,
119    /// Funding rate.
120    #[serde(default)]
121    pub funding_rate: NumberString,
122    /// Realized funding rate.
123    #[serde(default)]
124    pub realized_rate: NumberString,
125    /// Funding time (Unix milliseconds).
126    #[serde(default)]
127    pub funding_time: NumberString,
128    /// Funding method.
129    #[serde(default)]
130    pub method: String,
131}
132
133/// Price-limit information for an instrument.
134#[derive(Debug, Clone, Deserialize)]
135#[serde(rename_all = "camelCase")]
136#[non_exhaustive]
137pub struct PriceLimit {
138    /// Instrument type.
139    #[serde(default)]
140    pub inst_type: String,
141    /// Instrument ID.
142    pub inst_id: String,
143    /// Highest buy price.
144    #[serde(default)]
145    pub buy_lmt: NumberString,
146    /// Lowest sell price.
147    #[serde(default)]
148    pub sell_lmt: NumberString,
149    /// Whether the price limit is enabled.
150    #[serde(default)]
151    pub enabled: bool,
152    /// Timestamp (Unix milliseconds).
153    #[serde(default)]
154    pub ts: NumberString,
155}
156
157/// Mark-price information.
158#[derive(Debug, Clone, Deserialize)]
159#[serde(rename_all = "camelCase")]
160#[non_exhaustive]
161pub struct MarkPrice {
162    /// Instrument type.
163    pub inst_type: InstType,
164    /// Instrument ID.
165    pub inst_id: String,
166    /// Mark price.
167    #[serde(default)]
168    pub mark_px: NumberString,
169    /// Timestamp (Unix milliseconds).
170    #[serde(default)]
171    pub ts: NumberString,
172}
173
174/// Delivery/exercise history row.
175#[derive(Debug, Clone, Deserialize)]
176#[serde(rename_all = "camelCase")]
177#[non_exhaustive]
178pub struct DeliveryExercise {
179    /// Instrument type.
180    #[serde(default)]
181    pub inst_type: String,
182    /// Instrument ID.
183    #[serde(default)]
184    pub inst_id: String,
185    /// Delivery/exercise price.
186    #[serde(default)]
187    pub px: NumberString,
188    /// Delivery/exercise type.
189    #[serde(rename = "type", default)]
190    pub exercise_type: String,
191    /// Timestamp (Unix milliseconds).
192    #[serde(default)]
193    pub ts: NumberString,
194}
195
196/// Public position-tier information.
197#[derive(Debug, Clone, Deserialize)]
198#[serde(rename_all = "camelCase")]
199#[non_exhaustive]
200pub struct PositionTier {
201    /// Instrument type.
202    pub inst_type: InstType,
203    /// Trade mode.
204    #[serde(default)]
205    pub td_mode: String,
206    /// Instrument ID.
207    #[serde(default)]
208    pub inst_id: String,
209    /// Tier.
210    #[serde(default)]
211    pub tier: String,
212    /// Minimum size.
213    #[serde(default)]
214    pub min_sz: NumberString,
215    /// Maximum size.
216    #[serde(default)]
217    pub max_sz: NumberString,
218    /// Initial margin rate.
219    #[serde(default)]
220    pub imr: NumberString,
221    /// Maintenance margin rate.
222    #[serde(default)]
223    pub mmr: NumberString,
224}
225
226/// Insurance-fund snapshot.
227#[derive(Debug, Clone, Deserialize)]
228#[serde(rename_all = "camelCase")]
229#[non_exhaustive]
230pub struct InsuranceFund {
231    /// Instrument type.
232    #[serde(default)]
233    pub inst_type: String,
234    /// Fund type.
235    #[serde(rename = "type", default)]
236    pub fund_type: String,
237    /// Currency.
238    #[serde(default)]
239    pub ccy: String,
240    /// Balance amount.
241    #[serde(default)]
242    pub amt: NumberString,
243    /// Timestamp (Unix milliseconds).
244    #[serde(default)]
245    pub ts: NumberString,
246}
247
248/// Contract/coin conversion result.
249#[derive(Debug, Clone, Deserialize)]
250#[serde(rename_all = "camelCase")]
251#[non_exhaustive]
252pub struct ConvertContractCoin {
253    /// Instrument ID.
254    #[serde(default)]
255    pub inst_id: String,
256    /// Converted size.
257    #[serde(default)]
258    pub sz: NumberString,
259    /// Conversion price.
260    #[serde(default)]
261    pub px: NumberString,
262    /// Conversion unit.
263    #[serde(default)]
264    pub unit: String,
265}