Skip to main content

rust_okx/api/market/
requests.rs

1use serde::Serialize;
2
3/// Query parameters for historical/index/mark-price candlestick endpoints.
4#[derive(Debug, Clone, Serialize)]
5pub struct CandlesticksRequest {
6    #[serde(rename = "instId")]
7    inst_id: String,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    after: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    before: Option<String>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    bar: Option<String>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    limit: Option<u32>,
16}
17
18impl CandlesticksRequest {
19    /// Create a candlestick query for an instrument.
20    pub fn new(inst_id: impl Into<String>) -> Self {
21        Self {
22            inst_id: inst_id.into(),
23            after: None,
24            before: None,
25            bar: None,
26            limit: None,
27        }
28    }
29
30    /// Return records after this pagination cursor.
31    pub fn after(mut self, after: impl Into<String>) -> Self {
32        self.after = Some(after.into());
33        self
34    }
35
36    /// Return records before this pagination cursor.
37    pub fn before(mut self, before: impl Into<String>) -> Self {
38        self.before = Some(before.into());
39        self
40    }
41
42    /// Set the bar size, e.g. `1m`, `1H`, or `1D`.
43    pub fn bar(mut self, bar: impl Into<String>) -> Self {
44        self.bar = Some(bar.into());
45        self
46    }
47
48    /// Set the maximum number of rows to return.
49    pub fn limit(mut self, limit: u32) -> Self {
50        self.limit = Some(limit);
51        self
52    }
53}
54
55/// Query parameters for historical trades.
56#[derive(Debug, Clone, Serialize)]
57pub struct HistoryTradesRequest {
58    #[serde(rename = "instId")]
59    inst_id: String,
60    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
61    trade_type: Option<String>,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    after: Option<String>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    before: Option<String>,
66    #[serde(skip_serializing_if = "Option::is_none")]
67    limit: Option<u32>,
68}
69
70impl HistoryTradesRequest {
71    /// Create a historical trades query for an instrument.
72    pub fn new(inst_id: impl Into<String>) -> Self {
73        Self {
74            inst_id: inst_id.into(),
75            trade_type: None,
76            after: None,
77            before: None,
78            limit: None,
79        }
80    }
81
82    /// Set the OKX trade type filter.
83    pub fn trade_type(mut self, trade_type: impl Into<String>) -> Self {
84        self.trade_type = Some(trade_type.into());
85        self
86    }
87
88    /// Return records after this pagination cursor.
89    pub fn after(mut self, after: impl Into<String>) -> Self {
90        self.after = Some(after.into());
91        self
92    }
93
94    /// Return records before this pagination cursor.
95    pub fn before(mut self, before: impl Into<String>) -> Self {
96        self.before = Some(before.into());
97        self
98    }
99
100    /// Set the maximum number of rows to return.
101    pub fn limit(mut self, limit: u32) -> Self {
102        self.limit = Some(limit);
103        self
104    }
105}