rust_okx/api/account/requests/
history.rs1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::{InstType, TradeMode};
6
7#[derive(Debug, Clone, Default, Serialize)]
9pub struct BillsRequest<'a> {
10 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
11 inst_type: Option<InstType>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 ccy: Option<Cow<'a, str>>,
14 #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
15 mgn_mode: Option<TradeMode>,
16 #[serde(rename = "ctType", skip_serializing_if = "Option::is_none")]
17 ct_type: Option<Cow<'a, str>>,
18 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
19 bill_type: Option<Cow<'a, str>>,
20 #[serde(rename = "subType", skip_serializing_if = "Option::is_none")]
21 sub_type: Option<Cow<'a, str>>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 after: Option<Cow<'a, str>>,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 before: Option<Cow<'a, str>>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 begin: Option<Cow<'a, str>>,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 end: Option<Cow<'a, str>>,
30 #[serde(skip_serializing_if = "Option::is_none")]
31 limit: Option<u32>,
32}
33
34impl<'a> BillsRequest<'a> {
35 pub fn new() -> Self {
37 Self::default()
38 }
39
40 pub fn inst_type(mut self, inst_type: InstType) -> Self {
42 self.inst_type = Some(inst_type);
43 self
44 }
45
46 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
48 self.ccy = Some(ccy.into());
49 self
50 }
51
52 pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
54 self.mgn_mode = Some(mgn_mode);
55 self
56 }
57
58 pub fn contract_type(mut self, ct_type: impl Into<Cow<'a, str>>) -> Self {
60 self.ct_type = Some(ct_type.into());
61 self
62 }
63
64 pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
66 self.bill_type = Some(bill_type.into());
67 self
68 }
69
70 pub fn sub_type(mut self, sub_type: impl Into<Cow<'a, str>>) -> Self {
72 self.sub_type = Some(sub_type.into());
73 self
74 }
75
76 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
78 self.after = Some(after.into());
79 self
80 }
81
82 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
84 self.before = Some(before.into());
85 self
86 }
87
88 pub fn begin(mut self, begin: impl Into<Cow<'a, str>>) -> Self {
90 self.begin = Some(begin.into());
91 self
92 }
93
94 pub fn end(mut self, end: impl Into<Cow<'a, str>>) -> Self {
96 self.end = Some(end.into());
97 self
98 }
99
100 pub fn limit(mut self, limit: u32) -> Self {
102 self.limit = Some(limit);
103 self
104 }
105}
106
107#[derive(Debug, Clone, Default, Serialize)]
109pub struct BillsArchiveRequest<'a> {
110 #[serde(flatten)]
111 base: BillsRequest<'a>,
112 #[serde(skip_serializing_if = "Option::is_none")]
113 begin: Option<Cow<'a, str>>,
114 #[serde(skip_serializing_if = "Option::is_none")]
115 end: Option<Cow<'a, str>>,
116}
117
118impl<'a> BillsArchiveRequest<'a> {
119 pub fn new() -> Self {
121 Self::default()
122 }
123
124 pub fn filters(mut self, base: BillsRequest<'a>) -> Self {
126 self.base = base;
127 self
128 }
129
130 pub fn begin(mut self, begin: impl Into<Cow<'a, str>>) -> Self {
132 self.begin = Some(begin.into());
133 self
134 }
135
136 pub fn end(mut self, end: impl Into<Cow<'a, str>>) -> Self {
138 self.end = Some(end.into());
139 self
140 }
141}
142
143#[derive(Debug, Clone, Default, Serialize)]
145pub struct BillSubtypesRequest<'a> {
146 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
147 bill_type: Option<Cow<'a, str>>,
148}
149
150impl<'a> BillSubtypesRequest<'a> {
151 pub fn new() -> Self {
153 Self::default()
154 }
155
156 pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
158 self.bill_type = Some(bill_type.into());
159 self
160 }
161}
162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
165#[non_exhaustive]
166pub enum BillsHistoryArchiveQuarter {
167 #[serde(rename = "Q1")]
169 Q1,
170 #[serde(rename = "Q2")]
172 Q2,
173 #[serde(rename = "Q3")]
175 Q3,
176 #[serde(rename = "Q4")]
178 Q4,
179}
180
181#[derive(Debug, Clone, Serialize)]
183pub struct BillsHistoryArchiveRequest<'a> {
184 year: Cow<'a, str>,
185 quarter: BillsHistoryArchiveQuarter,
186 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
187 bill_type: Option<Cow<'a, str>>,
188}
189
190impl<'a> BillsHistoryArchiveRequest<'a> {
191 pub fn new(year: impl Into<Cow<'a, str>>, quarter: BillsHistoryArchiveQuarter) -> Self {
193 Self {
194 year: year.into(),
195 quarter,
196 bill_type: None,
197 }
198 }
199
200 pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
202 self.bill_type = Some(bill_type.into());
203 self
204 }
205}
206
207pub type ApplyBillsHistoryArchiveRequest<'a> = BillsHistoryArchiveRequest<'a>;
209
210#[derive(Debug, Clone, Default, Serialize)]
212pub struct PositionsHistoryRequest<'a> {
213 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
214 inst_type: Option<InstType>,
215 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
216 inst_id: Option<Cow<'a, str>>,
217 #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
218 mgn_mode: Option<TradeMode>,
219 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
220 close_type: Option<Cow<'a, str>>,
221 #[serde(rename = "posId", skip_serializing_if = "Option::is_none")]
222 pos_id: Option<Cow<'a, str>>,
223 #[serde(skip_serializing_if = "Option::is_none")]
224 after: Option<Cow<'a, str>>,
225 #[serde(skip_serializing_if = "Option::is_none")]
226 before: Option<Cow<'a, str>>,
227 #[serde(skip_serializing_if = "Option::is_none")]
228 limit: Option<u32>,
229}
230
231impl<'a> PositionsHistoryRequest<'a> {
232 pub fn new() -> Self {
234 Self::default()
235 }
236
237 pub fn inst_type(mut self, inst_type: InstType) -> Self {
239 self.inst_type = Some(inst_type);
240 self
241 }
242
243 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
245 self.inst_id = Some(inst_id.into());
246 self
247 }
248
249 pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
251 self.mgn_mode = Some(mgn_mode);
252 self
253 }
254
255 pub fn close_type(mut self, close_type: impl Into<Cow<'a, str>>) -> Self {
257 self.close_type = Some(close_type.into());
258 self
259 }
260
261 pub fn position_id(mut self, pos_id: impl Into<Cow<'a, str>>) -> Self {
263 self.pos_id = Some(pos_id.into());
264 self
265 }
266
267 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
269 self.after = Some(after.into());
270 self
271 }
272
273 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
275 self.before = Some(before.into());
276 self
277 }
278
279 pub fn limit(mut self, limit: u32) -> Self {
281 self.limit = Some(limit);
282 self
283 }
284}