rust_okx/api/account/requests/
trading.rs1use serde::Serialize;
2
3use crate::model::{InstType, PositionSide, TradeMode};
4
5#[derive(Debug, Clone, Serialize)]
7pub struct SetLeverageRequest {
8 lever: String,
9 #[serde(rename = "mgnMode")]
10 mgn_mode: TradeMode,
11 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
12 inst_id: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 ccy: Option<String>,
15 #[serde(rename = "posSide", skip_serializing_if = "Option::is_none")]
16 pos_side: Option<PositionSide>,
17}
18
19impl SetLeverageRequest {
20 pub fn new(lever: impl Into<String>, mgn_mode: TradeMode) -> Self {
22 Self {
23 lever: lever.into(),
24 mgn_mode,
25 inst_id: None,
26 ccy: None,
27 pos_side: None,
28 }
29 }
30
31 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
33 self.inst_id = Some(inst_id.into());
34 self
35 }
36
37 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
39 self.ccy = Some(ccy.into());
40 self
41 }
42
43 pub fn position_side(mut self, pos_side: PositionSide) -> Self {
45 self.pos_side = Some(pos_side);
46 self
47 }
48}
49
50#[derive(Debug, Clone, Serialize)]
52pub struct LeverageRequest {
53 #[serde(rename = "mgnMode")]
54 mgn_mode: TradeMode,
55 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
56 inst_id: Option<String>,
57 #[serde(skip_serializing_if = "Option::is_none")]
58 ccy: Option<String>,
59}
60
61impl LeverageRequest {
62 pub fn new(mgn_mode: TradeMode) -> Self {
64 Self {
65 mgn_mode,
66 inst_id: None,
67 ccy: None,
68 }
69 }
70
71 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
73 self.inst_id = Some(inst_id.into());
74 self
75 }
76
77 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
79 self.ccy = Some(ccy.into());
80 self
81 }
82}
83
84#[derive(Debug, Clone, Serialize)]
86pub struct MaxOrderSizeRequest {
87 #[serde(rename = "instId")]
88 inst_id: String,
89 #[serde(rename = "tdMode")]
90 td_mode: TradeMode,
91 #[serde(skip_serializing_if = "Option::is_none")]
92 ccy: Option<String>,
93 #[serde(skip_serializing_if = "Option::is_none")]
94 px: Option<String>,
95 #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
96 trade_quote_ccy: Option<String>,
97}
98
99impl MaxOrderSizeRequest {
100 pub fn new(inst_id: impl Into<String>, td_mode: TradeMode) -> Self {
102 Self {
103 inst_id: inst_id.into(),
104 td_mode,
105 ccy: None,
106 px: None,
107 trade_quote_ccy: None,
108 }
109 }
110
111 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
113 self.ccy = Some(ccy.into());
114 self
115 }
116
117 pub fn price(mut self, px: impl Into<String>) -> Self {
119 self.px = Some(px.into());
120 self
121 }
122
123 pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
125 self.trade_quote_ccy = Some(trade_quote_ccy.into());
126 self
127 }
128}
129
130#[derive(Debug, Clone, Serialize)]
132pub struct MaxAvailableSizeRequest {
133 #[serde(rename = "instId")]
134 inst_id: String,
135 #[serde(rename = "tdMode")]
136 td_mode: TradeMode,
137 #[serde(skip_serializing_if = "Option::is_none")]
138 ccy: Option<String>,
139 #[serde(rename = "reduceOnly", skip_serializing_if = "Option::is_none")]
140 reduce_only: Option<bool>,
141 #[serde(rename = "unSpotOffset", skip_serializing_if = "Option::is_none")]
142 un_spot_offset: Option<bool>,
143 #[serde(rename = "quickMgnType", skip_serializing_if = "Option::is_none")]
144 quick_mgn_type: Option<String>,
145 #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
146 trade_quote_ccy: Option<String>,
147}
148
149impl MaxAvailableSizeRequest {
150 pub fn new(inst_id: impl Into<String>, td_mode: TradeMode) -> Self {
152 Self {
153 inst_id: inst_id.into(),
154 td_mode,
155 ccy: None,
156 reduce_only: None,
157 un_spot_offset: None,
158 quick_mgn_type: None,
159 trade_quote_ccy: None,
160 }
161 }
162
163 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
165 self.ccy = Some(ccy.into());
166 self
167 }
168
169 pub fn reduce_only(mut self, reduce_only: bool) -> Self {
171 self.reduce_only = Some(reduce_only);
172 self
173 }
174
175 pub fn un_spot_offset(mut self, un_spot_offset: bool) -> Self {
177 self.un_spot_offset = Some(un_spot_offset);
178 self
179 }
180
181 pub fn quick_margin_type(mut self, quick_mgn_type: impl Into<String>) -> Self {
183 self.quick_mgn_type = Some(quick_mgn_type.into());
184 self
185 }
186
187 pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
189 self.trade_quote_ccy = Some(trade_quote_ccy.into());
190 self
191 }
192}
193
194#[derive(Debug, Clone, Serialize)]
196pub struct AdjustMarginRequest {
197 #[serde(rename = "instId")]
198 inst_id: String,
199 #[serde(rename = "posSide")]
200 pos_side: PositionSide,
201 #[serde(rename = "type")]
202 action: String,
203 amt: String,
204 #[serde(rename = "loanTrans", skip_serializing_if = "Option::is_none")]
205 loan_trans: Option<bool>,
206}
207
208impl AdjustMarginRequest {
209 pub fn new(
211 inst_id: impl Into<String>,
212 pos_side: PositionSide,
213 action: impl Into<String>,
214 amt: impl Into<String>,
215 ) -> Self {
216 Self {
217 inst_id: inst_id.into(),
218 pos_side,
219 action: action.into(),
220 amt: amt.into(),
221 loan_trans: None,
222 }
223 }
224
225 pub fn loan_transfer(mut self, loan_trans: bool) -> Self {
227 self.loan_trans = Some(loan_trans);
228 self
229 }
230}
231
232#[derive(Debug, Clone, Serialize)]
234pub struct FeeRatesRequest {
235 #[serde(rename = "instType")]
236 inst_type: InstType,
237 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
238 inst_id: Option<String>,
239 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
240 underlying: Option<String>,
241 #[serde(skip_serializing_if = "Option::is_none")]
242 category: Option<String>,
243 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
244 inst_family: Option<String>,
245}
246
247impl FeeRatesRequest {
248 pub fn new(inst_type: InstType) -> Self {
250 Self {
251 inst_type,
252 inst_id: None,
253 underlying: None,
254 category: None,
255 inst_family: None,
256 }
257 }
258
259 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
261 self.inst_id = Some(inst_id.into());
262 self
263 }
264
265 pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
267 self.underlying = Some(underlying.into());
268 self
269 }
270
271 pub fn category(mut self, category: impl Into<String>) -> Self {
273 self.category = Some(category.into());
274 self
275 }
276
277 pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
279 self.inst_family = Some(inst_family.into());
280 self
281 }
282}
283
284#[derive(Debug, Clone, Serialize)]
286pub struct AccountInstrumentsRequest {
287 #[serde(rename = "instType")]
288 inst_type: InstType,
289 #[serde(rename = "seriesId", skip_serializing_if = "Option::is_none")]
290 series_id: Option<String>,
291 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
292 inst_family: Option<String>,
293 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
294 inst_id: Option<String>,
295}
296
297impl AccountInstrumentsRequest {
298 pub fn new(inst_type: InstType) -> Self {
300 Self {
301 inst_type,
302 series_id: None,
303 inst_family: None,
304 inst_id: None,
305 }
306 }
307
308 pub fn series_id(mut self, series_id: impl Into<String>) -> Self {
310 self.series_id = Some(series_id.into());
311 self
312 }
313
314 pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
316 self.inst_family = Some(inst_family.into());
317 self
318 }
319
320 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
322 self.inst_id = Some(inst_id.into());
323 self
324 }
325}