1use serde::Serialize;
2
3use crate::model::{OrderSide, OrderState, OrderType, PositionSide, RequestParams, TradeMode};
4
5pub type AlgoOrderRequest = RequestParams;
7
8pub type CancelAlgoOrderRequest = RequestParams;
10
11pub type AmendAlgoOrderRequest = RequestParams;
13
14pub type AlgoOrderListRequest = RequestParams;
16
17pub type AlgoOrderHistoryRequest = RequestParams;
19
20pub type AlgoOrderDetailsRequest = RequestParams;
22
23pub type EasyConvertRequest = RequestParams;
25
26pub type EasyConvertHistoryRequest = RequestParams;
28
29pub type OneClickRepayCurrencyListRequest = RequestParams;
31
32pub type OneClickRepayRequest = RequestParams;
34
35pub type OneClickRepayHistoryRequest = RequestParams;
37
38#[derive(Debug, Clone, Serialize)]
44pub struct PlaceOrderRequest {
45 #[serde(rename = "instId")]
46 inst_id: String,
47 #[serde(rename = "tdMode")]
48 td_mode: TradeMode,
49 side: OrderSide,
50 #[serde(rename = "ordType")]
51 ord_type: OrderType,
52 sz: String,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 ccy: Option<String>,
55 #[serde(skip_serializing_if = "Option::is_none")]
56 tag: Option<String>,
57 #[serde(rename = "px", skip_serializing_if = "Option::is_none")]
58 px: Option<String>,
59 #[serde(rename = "posSide", skip_serializing_if = "Option::is_none")]
60 pos_side: Option<PositionSide>,
61 #[serde(rename = "clOrdId", skip_serializing_if = "Option::is_none")]
62 cl_ord_id: Option<String>,
63 #[serde(rename = "reduceOnly", skip_serializing_if = "Option::is_none")]
64 reduce_only: Option<bool>,
65 #[serde(rename = "tgtCcy", skip_serializing_if = "Option::is_none")]
66 tgt_ccy: Option<String>,
67}
68
69impl PlaceOrderRequest {
70 pub fn new(
72 inst_id: impl Into<String>,
73 td_mode: TradeMode,
74 side: OrderSide,
75 ord_type: OrderType,
76 sz: impl Into<String>,
77 ) -> Self {
78 Self {
79 inst_id: inst_id.into(),
80 td_mode,
81 side,
82 ord_type,
83 sz: sz.into(),
84 ccy: None,
85 tag: None,
86 px: None,
87 pos_side: None,
88 cl_ord_id: None,
89 reduce_only: None,
90 tgt_ccy: None,
91 }
92 }
93
94 pub fn price(mut self, px: impl Into<String>) -> Self {
96 self.px = Some(px.into());
97 self
98 }
99
100 pub fn position_side(mut self, pos_side: PositionSide) -> Self {
102 self.pos_side = Some(pos_side);
103 self
104 }
105
106 pub fn client_order_id(mut self, cl_ord_id: impl Into<String>) -> Self {
108 self.cl_ord_id = Some(cl_ord_id.into());
109 self
110 }
111
112 pub fn reduce_only(mut self, reduce_only: bool) -> Self {
114 self.reduce_only = Some(reduce_only);
115 self
116 }
117
118 pub fn target_ccy(mut self, tgt_ccy: impl Into<String>) -> Self {
120 self.tgt_ccy = Some(tgt_ccy.into());
121 self
122 }
123
124 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
126 self.ccy = Some(ccy.into());
127 self
128 }
129
130 pub fn tag(mut self, tag: impl Into<String>) -> Self {
132 self.tag = Some(tag.into());
133 self
134 }
135}
136
137#[derive(Debug, Clone, Serialize)]
139pub struct CancelOrderRequest {
140 #[serde(rename = "instId")]
141 inst_id: String,
142 #[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
143 ord_id: Option<String>,
144 #[serde(rename = "clOrdId", skip_serializing_if = "Option::is_none")]
145 cl_ord_id: Option<String>,
146}
147
148impl CancelOrderRequest {
149 pub fn by_order_id(inst_id: impl Into<String>, ord_id: impl Into<String>) -> Self {
151 Self {
152 inst_id: inst_id.into(),
153 ord_id: Some(ord_id.into()),
154 cl_ord_id: None,
155 }
156 }
157
158 pub fn by_client_order_id(inst_id: impl Into<String>, cl_ord_id: impl Into<String>) -> Self {
160 Self {
161 inst_id: inst_id.into(),
162 ord_id: None,
163 cl_ord_id: Some(cl_ord_id.into()),
164 }
165 }
166}
167
168#[derive(Debug, Clone, Serialize)]
170pub struct AmendOrderRequest {
171 #[serde(rename = "instId")]
172 inst_id: String,
173 #[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
174 ord_id: Option<String>,
175 #[serde(rename = "clOrdId", skip_serializing_if = "Option::is_none")]
176 cl_ord_id: Option<String>,
177 #[serde(rename = "reqId", skip_serializing_if = "Option::is_none")]
178 req_id: Option<String>,
179 #[serde(rename = "cxlOnFail", skip_serializing_if = "Option::is_none")]
180 cxl_on_fail: Option<bool>,
181 #[serde(rename = "newSz", skip_serializing_if = "Option::is_none")]
182 new_sz: Option<String>,
183 #[serde(rename = "newPx", skip_serializing_if = "Option::is_none")]
184 new_px: Option<String>,
185}
186
187impl AmendOrderRequest {
188 pub fn new(inst_id: impl Into<String>) -> Self {
190 Self {
191 inst_id: inst_id.into(),
192 ord_id: None,
193 cl_ord_id: None,
194 req_id: None,
195 cxl_on_fail: None,
196 new_sz: None,
197 new_px: None,
198 }
199 }
200
201 pub fn order_id(mut self, ord_id: impl Into<String>) -> Self {
203 self.ord_id = Some(ord_id.into());
204 self
205 }
206
207 pub fn client_order_id(mut self, cl_ord_id: impl Into<String>) -> Self {
209 self.cl_ord_id = Some(cl_ord_id.into());
210 self
211 }
212
213 pub fn request_id(mut self, req_id: impl Into<String>) -> Self {
215 self.req_id = Some(req_id.into());
216 self
217 }
218
219 pub fn cancel_on_fail(mut self, cxl_on_fail: bool) -> Self {
221 self.cxl_on_fail = Some(cxl_on_fail);
222 self
223 }
224
225 pub fn new_size(mut self, new_sz: impl Into<String>) -> Self {
227 self.new_sz = Some(new_sz.into());
228 self
229 }
230
231 pub fn new_price(mut self, new_px: impl Into<String>) -> Self {
233 self.new_px = Some(new_px.into());
234 self
235 }
236}
237
238#[derive(Debug, Clone, Serialize)]
240pub struct ClosePositionRequest {
241 #[serde(rename = "instId")]
242 inst_id: String,
243 #[serde(rename = "mgnMode")]
244 mgn_mode: TradeMode,
245 #[serde(rename = "posSide", skip_serializing_if = "Option::is_none")]
246 pos_side: Option<PositionSide>,
247 #[serde(skip_serializing_if = "Option::is_none")]
248 ccy: Option<String>,
249 #[serde(rename = "autoCxl", skip_serializing_if = "Option::is_none")]
250 auto_cancel: Option<bool>,
251 #[serde(rename = "clOrdId", skip_serializing_if = "Option::is_none")]
252 cl_ord_id: Option<String>,
253 #[serde(skip_serializing_if = "Option::is_none")]
254 tag: Option<String>,
255}
256
257impl ClosePositionRequest {
258 pub fn new(inst_id: impl Into<String>, mgn_mode: TradeMode) -> Self {
260 Self {
261 inst_id: inst_id.into(),
262 mgn_mode,
263 pos_side: None,
264 ccy: None,
265 auto_cancel: None,
266 cl_ord_id: None,
267 tag: None,
268 }
269 }
270
271 pub fn position_side(mut self, pos_side: PositionSide) -> Self {
273 self.pos_side = Some(pos_side);
274 self
275 }
276
277 pub fn currency(mut self, ccy: impl Into<String>) -> Self {
279 self.ccy = Some(ccy.into());
280 self
281 }
282
283 pub fn auto_cancel(mut self, auto_cancel: bool) -> Self {
285 self.auto_cancel = Some(auto_cancel);
286 self
287 }
288
289 pub fn client_order_id(mut self, cl_ord_id: impl Into<String>) -> Self {
291 self.cl_ord_id = Some(cl_ord_id.into());
292 self
293 }
294
295 pub fn tag(mut self, tag: impl Into<String>) -> Self {
297 self.tag = Some(tag.into());
298 self
299 }
300}
301
302#[derive(Debug, Clone, Default, Serialize)]
304pub struct OrderListRequest {
305 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
306 inst_type: Option<crate::model::InstType>,
307 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
308 underlying: Option<String>,
309 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
310 inst_id: Option<String>,
311 #[serde(rename = "ordType", skip_serializing_if = "Option::is_none")]
312 ord_type: Option<OrderType>,
313 #[serde(skip_serializing_if = "Option::is_none")]
314 state: Option<OrderState>,
315 #[serde(skip_serializing_if = "Option::is_none")]
316 after: Option<String>,
317 #[serde(skip_serializing_if = "Option::is_none")]
318 before: Option<String>,
319 #[serde(skip_serializing_if = "Option::is_none")]
320 limit: Option<u32>,
321 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
322 inst_family: Option<String>,
323}
324
325impl OrderListRequest {
326 pub fn new() -> Self {
328 Self::default()
329 }
330
331 pub fn inst_type(mut self, inst_type: crate::model::InstType) -> Self {
333 self.inst_type = Some(inst_type);
334 self
335 }
336
337 pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
339 self.underlying = Some(underlying.into());
340 self
341 }
342
343 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
345 self.inst_id = Some(inst_id.into());
346 self
347 }
348
349 pub fn order_type(mut self, ord_type: OrderType) -> Self {
351 self.ord_type = Some(ord_type);
352 self
353 }
354
355 pub fn state(mut self, state: OrderState) -> Self {
357 self.state = Some(state);
358 self
359 }
360
361 pub fn after(mut self, after: impl Into<String>) -> Self {
363 self.after = Some(after.into());
364 self
365 }
366
367 pub fn before(mut self, before: impl Into<String>) -> Self {
369 self.before = Some(before.into());
370 self
371 }
372
373 pub fn limit(mut self, limit: u32) -> Self {
375 self.limit = Some(limit);
376 self
377 }
378
379 pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
381 self.inst_family = Some(inst_family.into());
382 self
383 }
384}
385
386#[derive(Debug, Clone, Serialize)]
388pub struct OrderHistoryRequest {
389 #[serde(flatten)]
390 base: OrderListRequest,
391 #[serde(skip_serializing_if = "Option::is_none")]
392 begin: Option<String>,
393 #[serde(skip_serializing_if = "Option::is_none")]
394 end: Option<String>,
395}
396
397impl OrderHistoryRequest {
398 pub fn new(inst_type: crate::model::InstType) -> Self {
400 Self {
401 base: OrderListRequest::new().inst_type(inst_type),
402 begin: None,
403 end: None,
404 }
405 }
406
407 pub fn filters(mut self, base: OrderListRequest) -> Self {
409 self.base = base;
410 self
411 }
412
413 pub fn begin(mut self, begin: impl Into<String>) -> Self {
415 self.begin = Some(begin.into());
416 self
417 }
418
419 pub fn end(mut self, end: impl Into<String>) -> Self {
421 self.end = Some(end.into());
422 self
423 }
424}
425
426#[derive(Debug, Clone, Default, Serialize)]
428pub struct FillsRequest {
429 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
430 inst_type: Option<crate::model::InstType>,
431 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
432 underlying: Option<String>,
433 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
434 inst_id: Option<String>,
435 #[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
436 ord_id: Option<String>,
437 #[serde(skip_serializing_if = "Option::is_none")]
438 after: Option<String>,
439 #[serde(skip_serializing_if = "Option::is_none")]
440 before: Option<String>,
441 #[serde(skip_serializing_if = "Option::is_none")]
442 begin: Option<String>,
443 #[serde(skip_serializing_if = "Option::is_none")]
444 end: Option<String>,
445 #[serde(skip_serializing_if = "Option::is_none")]
446 limit: Option<u32>,
447 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
448 inst_family: Option<String>,
449}
450
451impl FillsRequest {
452 pub fn new() -> Self {
454 Self::default()
455 }
456
457 pub fn inst_type(mut self, inst_type: crate::model::InstType) -> Self {
459 self.inst_type = Some(inst_type);
460 self
461 }
462
463 pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
465 self.underlying = Some(underlying.into());
466 self
467 }
468
469 pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
471 self.inst_id = Some(inst_id.into());
472 self
473 }
474
475 pub fn order_id(mut self, ord_id: impl Into<String>) -> Self {
477 self.ord_id = Some(ord_id.into());
478 self
479 }
480
481 pub fn after(mut self, after: impl Into<String>) -> Self {
483 self.after = Some(after.into());
484 self
485 }
486
487 pub fn before(mut self, before: impl Into<String>) -> Self {
489 self.before = Some(before.into());
490 self
491 }
492
493 pub fn begin(mut self, begin: impl Into<String>) -> Self {
495 self.begin = Some(begin.into());
496 self
497 }
498
499 pub fn end(mut self, end: impl Into<String>) -> Self {
501 self.end = Some(end.into());
502 self
503 }
504
505 pub fn limit(mut self, limit: u32) -> Self {
507 self.limit = Some(limit);
508 self
509 }
510
511 pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
513 self.inst_family = Some(inst_family.into());
514 self
515 }
516}