Skip to main content

rust_okx/api/public_data/
requests.rs

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