Skip to main content

rust_okx/api/public_data/
requests.rs

1use serde::Serialize;
2
3use crate::model::InstType;
4
5mod edge;
6
7pub use edge::*;
8/// Query parameters for public endpoints filtered by instrument family.
9#[derive(Debug, Clone, Serialize)]
10pub struct InstrumentFamilyRequest {
11    #[serde(rename = "instType")]
12    inst_type: InstType,
13    #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
14    underlying: Option<String>,
15    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
16    inst_id: Option<String>,
17    #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
18    inst_family: Option<String>,
19}
20
21impl InstrumentFamilyRequest {
22    /// Create a query for an instrument type.
23    pub fn new(inst_type: InstType) -> Self {
24        Self {
25            inst_type,
26            underlying: None,
27            inst_id: None,
28            inst_family: None,
29        }
30    }
31
32    /// Set the underlying filter.
33    pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
34        self.underlying = Some(underlying.into());
35        self
36    }
37
38    /// Set the instrument ID filter.
39    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
40        self.inst_id = Some(inst_id.into());
41        self
42    }
43
44    /// Set the instrument family filter.
45    pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
46        self.inst_family = Some(inst_family.into());
47        self
48    }
49}
50
51/// Query parameters for funding-rate history.
52#[derive(Debug, Clone, Serialize)]
53pub struct FundingRateHistoryRequest {
54    #[serde(rename = "instId")]
55    inst_id: String,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    after: Option<String>,
58    #[serde(skip_serializing_if = "Option::is_none")]
59    before: Option<String>,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    limit: Option<u32>,
62}
63
64impl FundingRateHistoryRequest {
65    /// Create a funding-rate history query.
66    pub fn new(inst_id: impl Into<String>) -> Self {
67        Self {
68            inst_id: inst_id.into(),
69            after: None,
70            before: None,
71            limit: None,
72        }
73    }
74
75    /// Return records after this pagination cursor.
76    pub fn after(mut self, after: impl Into<String>) -> Self {
77        self.after = Some(after.into());
78        self
79    }
80
81    /// Return records before this pagination cursor.
82    pub fn before(mut self, before: impl Into<String>) -> Self {
83        self.before = Some(before.into());
84        self
85    }
86
87    /// Set the maximum number of rows to return.
88    pub fn limit(mut self, limit: u32) -> Self {
89        self.limit = Some(limit);
90        self
91    }
92}
93
94/// Query parameters for delivery/exercise history.
95#[derive(Debug, Clone, Serialize)]
96pub struct DeliveryExerciseHistoryRequest {
97    #[serde(rename = "instType")]
98    inst_type: InstType,
99    #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
100    underlying: Option<String>,
101    #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
102    inst_family: Option<String>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    after: Option<String>,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    before: Option<String>,
107    #[serde(skip_serializing_if = "Option::is_none")]
108    limit: Option<u32>,
109}
110
111impl DeliveryExerciseHistoryRequest {
112    /// Create a delivery/exercise history query.
113    pub fn new(inst_type: InstType) -> Self {
114        Self {
115            inst_type,
116            underlying: None,
117            inst_family: None,
118            after: None,
119            before: None,
120            limit: None,
121        }
122    }
123
124    /// Set the underlying filter.
125    pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
126        self.underlying = Some(underlying.into());
127        self
128    }
129
130    /// Set the instrument family filter.
131    pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
132        self.inst_family = Some(inst_family.into());
133        self
134    }
135
136    /// Return records after this pagination cursor.
137    pub fn after(mut self, after: impl Into<String>) -> Self {
138        self.after = Some(after.into());
139        self
140    }
141
142    /// Return records before this pagination cursor.
143    pub fn before(mut self, before: impl Into<String>) -> Self {
144        self.before = Some(before.into());
145        self
146    }
147
148    /// Set the maximum number of rows to return.
149    pub fn limit(mut self, limit: u32) -> Self {
150        self.limit = Some(limit);
151        self
152    }
153}
154
155/// Query parameters for public position tiers.
156#[derive(Debug, Clone, Serialize)]
157pub struct PositionTiersRequest {
158    #[serde(rename = "instType")]
159    inst_type: InstType,
160    #[serde(rename = "tdMode")]
161    td_mode: String,
162    #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
163    underlying: Option<String>,
164    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
165    inst_id: Option<String>,
166    #[serde(skip_serializing_if = "Option::is_none")]
167    ccy: Option<String>,
168    #[serde(skip_serializing_if = "Option::is_none")]
169    tier: Option<String>,
170    #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
171    inst_family: Option<String>,
172}
173
174impl PositionTiersRequest {
175    /// Create a position-tiers query.
176    pub fn new(inst_type: InstType, td_mode: impl Into<String>) -> Self {
177        Self {
178            inst_type,
179            td_mode: td_mode.into(),
180            underlying: None,
181            inst_id: None,
182            ccy: None,
183            tier: None,
184            inst_family: None,
185        }
186    }
187
188    /// Set the underlying filter.
189    pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
190        self.underlying = Some(underlying.into());
191        self
192    }
193
194    /// Set the instrument ID filter.
195    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
196        self.inst_id = Some(inst_id.into());
197        self
198    }
199
200    /// Set the currency filter.
201    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
202        self.ccy = Some(ccy.into());
203        self
204    }
205
206    /// Set the tier filter.
207    pub fn tier(mut self, tier: impl Into<String>) -> Self {
208        self.tier = Some(tier.into());
209        self
210    }
211
212    /// Set the instrument family filter.
213    pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
214        self.inst_family = Some(inst_family.into());
215        self
216    }
217}
218
219/// Query parameters for insurance fund snapshots.
220#[derive(Debug, Clone, Serialize)]
221pub struct InsuranceFundRequest {
222    #[serde(rename = "instType")]
223    inst_type: InstType,
224    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
225    fund_type: Option<String>,
226    #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
227    underlying: Option<String>,
228    #[serde(skip_serializing_if = "Option::is_none")]
229    ccy: Option<String>,
230    #[serde(skip_serializing_if = "Option::is_none")]
231    before: Option<String>,
232    #[serde(skip_serializing_if = "Option::is_none")]
233    after: Option<String>,
234    #[serde(skip_serializing_if = "Option::is_none")]
235    limit: Option<u32>,
236    #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
237    inst_family: Option<String>,
238}
239
240impl InsuranceFundRequest {
241    /// Create an insurance fund query.
242    pub fn new(inst_type: InstType) -> Self {
243        Self {
244            inst_type,
245            fund_type: None,
246            underlying: None,
247            ccy: None,
248            before: None,
249            after: None,
250            limit: None,
251            inst_family: None,
252        }
253    }
254
255    /// Set the OKX fund type filter.
256    pub fn fund_type(mut self, fund_type: impl Into<String>) -> Self {
257        self.fund_type = Some(fund_type.into());
258        self
259    }
260
261    /// Set the underlying filter.
262    pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
263        self.underlying = Some(underlying.into());
264        self
265    }
266
267    /// Set the currency filter.
268    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
269        self.ccy = Some(ccy.into());
270        self
271    }
272
273    /// Return records before this pagination cursor.
274    pub fn before(mut self, before: impl Into<String>) -> Self {
275        self.before = Some(before.into());
276        self
277    }
278
279    /// Return records after this pagination cursor.
280    pub fn after(mut self, after: impl Into<String>) -> Self {
281        self.after = Some(after.into());
282        self
283    }
284
285    /// Set the maximum number of rows to return.
286    pub fn limit(mut self, limit: u32) -> Self {
287        self.limit = Some(limit);
288        self
289    }
290
291    /// Set the instrument family filter.
292    pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
293        self.inst_family = Some(inst_family.into());
294        self
295    }
296}
297
298/// Query parameters for contract/coin conversion.
299#[derive(Debug, Clone, Serialize)]
300pub struct ConvertContractCoinRequest {
301    #[serde(rename = "type")]
302    conversion_type: String,
303    #[serde(rename = "instId")]
304    inst_id: String,
305    sz: String,
306    #[serde(skip_serializing_if = "Option::is_none")]
307    px: Option<String>,
308    #[serde(skip_serializing_if = "Option::is_none")]
309    unit: Option<String>,
310}
311
312impl ConvertContractCoinRequest {
313    /// Create a contract/coin conversion query.
314    pub fn new(
315        conversion_type: impl Into<String>,
316        inst_id: impl Into<String>,
317        sz: impl Into<String>,
318    ) -> Self {
319        Self {
320            conversion_type: conversion_type.into(),
321            inst_id: inst_id.into(),
322            sz: sz.into(),
323            px: None,
324            unit: None,
325        }
326    }
327
328    /// Set the price used for conversion.
329    pub fn price(mut self, px: impl Into<String>) -> Self {
330        self.px = Some(px.into());
331        self
332    }
333
334    /// Set the unit used for conversion.
335    pub fn unit(mut self, unit: impl Into<String>) -> Self {
336        self.unit = Some(unit.into());
337        self
338    }
339}