Skip to main content

rust_okx/api/account/requests/
history.rs

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