Skip to main content

rust_okx/api/public_data/responses/
edge.rs

1use crate::model::{NumberString, deserialize_vec_or_empty_string};
2use serde::Deserialize;
3
4/// Option summary row.
5#[derive(Debug, Clone, Deserialize)]
6#[serde(rename_all = "camelCase")]
7#[non_exhaustive]
8pub struct OptionSummary {
9    /// Value returned by OKX in the `instType` field.
10    #[serde(default)]
11    pub inst_type: String,
12    /// Value returned by OKX in the `instId` field.
13    #[serde(default)]
14    pub inst_id: String,
15    /// Value returned by OKX in the `uly` field.
16    #[serde(default)]
17    pub uly: String,
18    /// Value returned by OKX in the `instFamily` field.
19    #[serde(default)]
20    pub inst_family: String,
21    /// Value returned by OKX in the `delta` field.
22    #[serde(default)]
23    pub delta: NumberString,
24    /// Value returned by OKX in the `gamma` field.
25    #[serde(default)]
26    pub gamma: NumberString,
27    /// Value returned by OKX in the `vega` field.
28    #[serde(default)]
29    pub vega: NumberString,
30    /// Value returned by OKX in the `theta` field.
31    #[serde(default)]
32    pub theta: NumberString,
33    /// Value returned by OKX in the `deltaBs` field.
34    #[serde(default)]
35    pub delta_bs: NumberString,
36    /// Value returned by OKX in the `gammaBs` field.
37    #[serde(default)]
38    pub gamma_bs: NumberString,
39    /// Value returned by OKX in the `vegaBs` field.
40    #[serde(default)]
41    pub vega_bs: NumberString,
42    /// Value returned by OKX in the `thetaBs` field.
43    #[serde(default)]
44    pub theta_bs: NumberString,
45    /// Value returned by OKX in the `lever` field.
46    #[serde(default)]
47    pub lever: NumberString,
48    /// Value returned by OKX in the `markVol` field.
49    #[serde(default)]
50    pub mark_vol: NumberString,
51    /// Value returned by OKX in the `realVol` field.
52    #[serde(default)]
53    pub real_vol: NumberString,
54    /// Value returned by OKX in the `volLv` field.
55    #[serde(default)]
56    pub vol_lv: NumberString,
57    /// Value returned by OKX in the `bidVol` field.
58    #[serde(default)]
59    pub bid_vol: NumberString,
60    /// Value returned by OKX in the `askVol` field.
61    #[serde(default)]
62    pub ask_vol: NumberString,
63    /// Value returned by OKX in the `fwdPx` field.
64    #[serde(default)]
65    pub fwd_px: NumberString,
66    /// Value returned by OKX in the `ts` field.
67    #[serde(default)]
68    pub ts: NumberString,
69}
70
71/// Estimated delivery or exercise price row.
72#[derive(Debug, Clone, Deserialize)]
73#[serde(rename_all = "camelCase")]
74#[non_exhaustive]
75pub struct EstimatedPrice {
76    /// Value returned by OKX in the `instType` field.
77    #[serde(default)]
78    pub inst_type: String,
79    /// Value returned by OKX in the `instId` field.
80    #[serde(default)]
81    pub inst_id: String,
82    /// Value returned by OKX in the `settlePx` field.
83    #[serde(default)]
84    pub settle_px: NumberString,
85    /// Value returned by OKX in the `ts` field.
86    #[serde(default)]
87    pub ts: NumberString,
88}
89
90/// Discount tier returned for interest-free quota calculations.
91#[derive(Debug, Clone, Deserialize)]
92#[serde(rename_all = "camelCase")]
93#[non_exhaustive]
94pub struct DiscountLevel {
95    /// Value returned by OKX in the `discountRate` field.
96    #[serde(default)]
97    pub discount_rate: NumberString,
98    /// Value returned by OKX in the `minAmt` field.
99    #[serde(default)]
100    pub min_amt: NumberString,
101    /// Value returned by OKX in the `maxAmt` field.
102    #[serde(default)]
103    pub max_amt: NumberString,
104}
105
106/// Discount-rate and interest-free quota row.
107#[derive(Debug, Clone, Deserialize)]
108#[serde(rename_all = "camelCase")]
109#[non_exhaustive]
110pub struct DiscountRateInterestFreeQuota {
111    /// Value returned by OKX in the `ccy` field.
112    #[serde(default)]
113    pub ccy: String,
114    /// Value returned by OKX in the `amt` field.
115    #[serde(default)]
116    pub amt: NumberString,
117    /// Value returned by OKX in the `discountLv` field.
118    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
119    pub discount_lv: Vec<DiscountLevel>,
120}
121
122/// Per-currency base rate and quota.
123#[derive(Debug, Clone, Deserialize)]
124#[serde(rename_all = "camelCase")]
125#[non_exhaustive]
126pub struct LoanQuotaBasic {
127    /// Value returned by OKX in the `ccy` field.
128    #[serde(default)]
129    pub ccy: String,
130    /// Value returned by OKX in the `rate` field.
131    #[serde(default)]
132    pub rate: NumberString,
133    /// Value returned by OKX in the `quota` field.
134    #[serde(default)]
135    pub quota: NumberString,
136}
137
138/// User-level quota coefficient.
139#[derive(Debug, Clone, Deserialize)]
140#[serde(rename_all = "camelCase")]
141#[non_exhaustive]
142pub struct LoanQuotaLevel {
143    /// Value returned by OKX in the `level` field.
144    #[serde(default)]
145    pub level: String,
146    /// Value returned by OKX in the `loanQuotaCoef` field.
147    #[serde(default)]
148    pub loan_quota_coef: NumberString,
149    /// Value returned by OKX in the `irDiscount` field.
150    #[serde(default)]
151    pub ir_discount: NumberString,
152}
153
154/// Currency with a customized interest rate.
155#[derive(Debug, Clone, Deserialize)]
156#[serde(rename_all = "camelCase")]
157#[non_exhaustive]
158pub struct LoanQuotaConfiguredCurrency {
159    /// Value returned by OKX in the `ccy` field.
160    #[serde(default)]
161    pub ccy: String,
162    /// Value returned by OKX in the `rate` field.
163    #[serde(default)]
164    pub rate: NumberString,
165}
166
167/// Customized absolute loan quota.
168#[derive(Debug, Clone, Deserialize)]
169#[serde(rename_all = "camelCase")]
170#[non_exhaustive]
171pub struct LoanQuotaConfig {
172    /// Value returned by OKX in the `ccy` field.
173    #[serde(default)]
174    pub ccy: String,
175    /// Value returned by OKX in the `stgyType` field.
176    #[serde(default)]
177    pub stgy_type: String,
178    /// Value returned by OKX in the `quota` field.
179    #[serde(default)]
180    pub quota: NumberString,
181    /// Value returned by OKX in the `level` field.
182    #[serde(default)]
183    pub level: String,
184}
185
186/// Interest-rate and loan-quota response row.
187#[derive(Debug, Clone, Deserialize)]
188#[serde(rename_all = "camelCase")]
189#[non_exhaustive]
190pub struct InterestRateLoanQuota {
191    /// Value returned by OKX in the `basic` field.
192    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
193    pub basic: Vec<LoanQuotaBasic>,
194    /// Value returned by OKX in the `vip` field.
195    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
196    pub vip: Vec<LoanQuotaLevel>,
197    /// Value returned by OKX in the `regular` field.
198    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
199    pub regular: Vec<LoanQuotaLevel>,
200    /// Value returned by OKX in the `configCcyList` field.
201    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
202    pub config_ccy_list: Vec<LoanQuotaConfiguredCurrency>,
203    /// Value returned by OKX in the `config` field.
204    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
205    pub config: Vec<LoanQuotaConfig>,
206}
207
208/// VIP interest-rate loan quota row.
209#[derive(Debug, Clone, Deserialize)]
210#[serde(rename_all = "camelCase")]
211#[non_exhaustive]
212pub struct VipInterestRateLoanQuota {
213    /// Value returned by OKX in the `ccy` field.
214    #[serde(default)]
215    pub ccy: String,
216    /// Value returned by OKX in the `level` field.
217    #[serde(default)]
218    pub level: String,
219    /// Value returned by OKX in the `rate` field.
220    #[serde(default)]
221    pub rate: NumberString,
222    /// Value returned by OKX in the `quota` field.
223    #[serde(default)]
224    pub quota: NumberString,
225}
226
227/// A single price range and tick-size definition.
228#[derive(Debug, Clone, Deserialize)]
229#[serde(rename_all = "camelCase")]
230#[non_exhaustive]
231pub struct TickBandDetail {
232    /// Value returned by OKX in the `minPx` field.
233    #[serde(default)]
234    pub min_px: NumberString,
235    /// Value returned by OKX in the `maxPx` field.
236    #[serde(default)]
237    pub max_px: NumberString,
238    /// Value returned by OKX in the `tickSz` field.
239    #[serde(default)]
240    pub tick_sz: NumberString,
241}
242
243/// Instrument tick-band row.
244#[derive(Debug, Clone, Deserialize)]
245#[serde(rename_all = "camelCase")]
246#[non_exhaustive]
247pub struct InstrumentTickBand {
248    /// Value returned by OKX in the `instType` field.
249    #[serde(default)]
250    pub inst_type: String,
251    /// Value returned by OKX in the `instFamily` field.
252    #[serde(default)]
253    pub inst_family: String,
254    /// Value returned by OKX in the `tickBand` field.
255    #[serde(default, deserialize_with = "deserialize_vec_or_empty_string")]
256    pub tick_band: Vec<TickBandDetail>,
257    /// Value returned by OKX in the `ts` field.
258    #[serde(default)]
259    pub ts: NumberString,
260}
261
262/// Public option-trade row.
263#[derive(Debug, Clone, Deserialize)]
264#[serde(rename_all = "camelCase")]
265#[non_exhaustive]
266pub struct PublicOptionTrade {
267    /// Value returned by OKX in the `instId` field.
268    #[serde(default)]
269    pub inst_id: String,
270    /// Value returned by OKX in the `tradeId` field.
271    #[serde(default)]
272    pub trade_id: String,
273    /// Value returned by OKX in the `px` field.
274    #[serde(default)]
275    pub px: NumberString,
276    /// Value returned by OKX in the `sz` field.
277    #[serde(default)]
278    pub sz: NumberString,
279    /// Value returned by OKX in the `side` field.
280    #[serde(default)]
281    pub side: String,
282    /// Value returned by OKX in the `fillVol` field.
283    #[serde(default)]
284    pub fill_vol: NumberString,
285    /// Value returned by OKX in the `fwdPx` field.
286    #[serde(default)]
287    pub fwd_px: NumberString,
288    /// Value returned by OKX in the `idxPx` field.
289    #[serde(default)]
290    pub idx_px: NumberString,
291    /// Value returned by OKX in the `markPx` field.
292    #[serde(default)]
293    pub mark_px: NumberString,
294    /// Value returned by OKX in the `ts` field.
295    #[serde(default)]
296    pub ts: NumberString,
297}
298
299/// Market-data history row.
300#[derive(Debug, Clone, Deserialize)]
301#[serde(rename_all = "camelCase")]
302#[non_exhaustive]
303pub struct MarketDataHistory {
304    /// Value returned by OKX in the `module` field.
305    #[serde(default)]
306    pub module: String,
307    /// Value returned by OKX in the `instType` field.
308    #[serde(default)]
309    pub inst_type: String,
310    /// Value returned by OKX in the `instId` field.
311    #[serde(default)]
312    pub inst_id: String,
313    /// Value returned by OKX in the `dateAggrType` field.
314    #[serde(default)]
315    pub date_aggr_type: String,
316    /// Value returned by OKX in the `value` field.
317    #[serde(default)]
318    pub value: NumberString,
319    /// Value returned by OKX in the `ts` field.
320    #[serde(default)]
321    pub ts: NumberString,
322}
323
324#[cfg(test)]
325mod tests {
326    use super::*;
327
328    #[test]
329    fn option_summary_ignores_future_fields() {
330        let row: OptionSummary = serde_json::from_str(
331            r#"{"instType":"OPTION","instId":"BTC-USD-1-C","delta":"0.5","futureField":"ok"}"#,
332        )
333        .unwrap();
334        assert_eq!(row.inst_type, "OPTION");
335        assert_eq!(row.inst_id, "BTC-USD-1-C");
336    }
337}