Skip to main content

rust_okx/api/account/requests/
history.rs

1use serde::Serialize;
2
3use crate::model::{InstType, TradeMode};
4
5/// Query parameters for account bills.
6#[derive(Debug, Clone, Default, Serialize)]
7pub struct BillsRequest {
8    #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
9    inst_type: Option<InstType>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    ccy: Option<String>,
12    #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
13    mgn_mode: Option<TradeMode>,
14    #[serde(rename = "ctType", skip_serializing_if = "Option::is_none")]
15    ct_type: Option<String>,
16    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
17    bill_type: Option<String>,
18    #[serde(rename = "subType", skip_serializing_if = "Option::is_none")]
19    sub_type: Option<String>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    after: Option<String>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    before: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    limit: Option<u32>,
26}
27
28impl BillsRequest {
29    /// Create an empty account-bills query.
30    pub fn new() -> Self {
31        Self::default()
32    }
33
34    /// Set the instrument type filter.
35    pub fn inst_type(mut self, inst_type: InstType) -> Self {
36        self.inst_type = Some(inst_type);
37        self
38    }
39
40    /// Set the currency filter.
41    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
42        self.ccy = Some(ccy.into());
43        self
44    }
45
46    /// Set the margin mode filter.
47    pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
48        self.mgn_mode = Some(mgn_mode);
49        self
50    }
51
52    /// Set the contract type filter.
53    pub fn contract_type(mut self, ct_type: impl Into<String>) -> Self {
54        self.ct_type = Some(ct_type.into());
55        self
56    }
57
58    /// Set the bill type filter.
59    pub fn bill_type(mut self, bill_type: impl Into<String>) -> Self {
60        self.bill_type = Some(bill_type.into());
61        self
62    }
63
64    /// Set the bill subtype filter.
65    pub fn sub_type(mut self, sub_type: impl Into<String>) -> Self {
66        self.sub_type = Some(sub_type.into());
67        self
68    }
69
70    /// Return records after this pagination cursor.
71    pub fn after(mut self, after: impl Into<String>) -> Self {
72        self.after = Some(after.into());
73        self
74    }
75
76    /// Return records before this pagination cursor.
77    pub fn before(mut self, before: impl Into<String>) -> Self {
78        self.before = Some(before.into());
79        self
80    }
81
82    /// Set the maximum number of rows to return.
83    pub fn limit(mut self, limit: u32) -> Self {
84        self.limit = Some(limit);
85        self
86    }
87}
88
89/// Query parameters for archived account bills.
90#[derive(Debug, Clone, Default, Serialize)]
91pub struct BillsArchiveRequest {
92    #[serde(flatten)]
93    base: BillsRequest,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    begin: Option<String>,
96    #[serde(skip_serializing_if = "Option::is_none")]
97    end: Option<String>,
98}
99
100impl BillsArchiveRequest {
101    /// Create an empty archived-bills query.
102    pub fn new() -> Self {
103        Self::default()
104    }
105
106    /// Set the common bills filters.
107    pub fn filters(mut self, base: BillsRequest) -> Self {
108        self.base = base;
109        self
110    }
111
112    /// Set the begin timestamp.
113    pub fn begin(mut self, begin: impl Into<String>) -> Self {
114        self.begin = Some(begin.into());
115        self
116    }
117
118    /// Set the end timestamp.
119    pub fn end(mut self, end: impl Into<String>) -> Self {
120        self.end = Some(end.into());
121        self
122    }
123}
124
125/// Query parameters for position history.
126#[derive(Debug, Clone, Default, Serialize)]
127pub struct PositionsHistoryRequest {
128    #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
129    inst_type: Option<InstType>,
130    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
131    inst_id: Option<String>,
132    #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
133    mgn_mode: Option<TradeMode>,
134    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
135    close_type: Option<String>,
136    #[serde(rename = "posId", skip_serializing_if = "Option::is_none")]
137    pos_id: Option<String>,
138    #[serde(skip_serializing_if = "Option::is_none")]
139    after: Option<String>,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    before: Option<String>,
142    #[serde(skip_serializing_if = "Option::is_none")]
143    limit: Option<u32>,
144}
145
146impl PositionsHistoryRequest {
147    /// Create an empty position-history query.
148    pub fn new() -> Self {
149        Self::default()
150    }
151
152    /// Set the instrument type filter.
153    pub fn inst_type(mut self, inst_type: InstType) -> Self {
154        self.inst_type = Some(inst_type);
155        self
156    }
157
158    /// Set the instrument ID filter.
159    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
160        self.inst_id = Some(inst_id.into());
161        self
162    }
163
164    /// Set the margin mode filter.
165    pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
166        self.mgn_mode = Some(mgn_mode);
167        self
168    }
169
170    /// Set the OKX close type filter.
171    pub fn close_type(mut self, close_type: impl Into<String>) -> Self {
172        self.close_type = Some(close_type.into());
173        self
174    }
175
176    /// Set the position ID filter.
177    pub fn position_id(mut self, pos_id: impl Into<String>) -> Self {
178        self.pos_id = Some(pos_id.into());
179        self
180    }
181
182    /// Return records after this pagination cursor.
183    pub fn after(mut self, after: impl Into<String>) -> Self {
184        self.after = Some(after.into());
185        self
186    }
187
188    /// Return records before this pagination cursor.
189    pub fn before(mut self, before: impl Into<String>) -> Self {
190        self.before = Some(before.into());
191        self
192    }
193
194    /// Set the maximum number of rows to return.
195    pub fn limit(mut self, limit: u32) -> Self {
196        self.limit = Some(limit);
197        self
198    }
199}