1use serde::Serialize;
19
20use crate::{
21 common::enums::{BinanceSelfTradePreventionMode, BinanceSide, BinanceTimeInForce},
22 spot::enums::{BinanceCancelReplaceMode, BinanceOrderResponseType, BinanceSpotOrderType},
23};
24
25#[derive(Debug, Clone, Serialize)]
27pub struct DepthParams {
28 pub symbol: String,
30 #[serde(skip_serializing_if = "Option::is_none")]
32 pub limit: Option<u32>,
33}
34
35impl DepthParams {
36 #[must_use]
38 pub fn new(symbol: impl Into<String>) -> Self {
39 Self {
40 symbol: symbol.into(),
41 limit: None,
42 }
43 }
44
45 #[must_use]
47 pub fn with_limit(mut self, limit: u32) -> Self {
48 self.limit = Some(limit);
49 self
50 }
51}
52
53#[derive(Debug, Clone, Serialize)]
55pub struct TradesParams {
56 pub symbol: String,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 pub limit: Option<u32>,
61}
62
63impl TradesParams {
64 #[must_use]
66 pub fn new(symbol: impl Into<String>) -> Self {
67 Self {
68 symbol: symbol.into(),
69 limit: None,
70 }
71 }
72
73 #[must_use]
75 pub fn with_limit(mut self, limit: u32) -> Self {
76 self.limit = Some(limit);
77 self
78 }
79}
80
81#[derive(Debug, Clone, Serialize)]
83pub struct NewOrderParams {
84 pub symbol: String,
86 pub side: BinanceSide,
88 #[serde(rename = "type")]
90 pub order_type: BinanceSpotOrderType,
91 #[serde(skip_serializing_if = "Option::is_none", rename = "timeInForce")]
93 pub time_in_force: Option<BinanceTimeInForce>,
94 #[serde(skip_serializing_if = "Option::is_none")]
96 pub quantity: Option<String>,
97 #[serde(skip_serializing_if = "Option::is_none", rename = "quoteOrderQty")]
99 pub quote_order_qty: Option<String>,
100 #[serde(skip_serializing_if = "Option::is_none")]
102 pub price: Option<String>,
103 #[serde(skip_serializing_if = "Option::is_none", rename = "newClientOrderId")]
105 pub new_client_order_id: Option<String>,
106 #[serde(skip_serializing_if = "Option::is_none", rename = "stopPrice")]
108 pub stop_price: Option<String>,
109 #[serde(skip_serializing_if = "Option::is_none", rename = "trailingDelta")]
111 pub trailing_delta: Option<i64>,
112 #[serde(skip_serializing_if = "Option::is_none", rename = "icebergQty")]
114 pub iceberg_qty: Option<String>,
115 #[serde(skip_serializing_if = "Option::is_none", rename = "newOrderRespType")]
117 pub new_order_resp_type: Option<BinanceOrderResponseType>,
118 #[serde(
120 skip_serializing_if = "Option::is_none",
121 rename = "selfTradePreventionMode"
122 )]
123 pub self_trade_prevention_mode: Option<BinanceSelfTradePreventionMode>,
124}
125
126impl NewOrderParams {
127 #[must_use]
129 pub fn limit(
130 symbol: impl Into<String>,
131 side: BinanceSide,
132 quantity: impl Into<String>,
133 price: impl Into<String>,
134 ) -> Self {
135 Self {
136 symbol: symbol.into(),
137 side,
138 order_type: BinanceSpotOrderType::Limit,
139 time_in_force: Some(BinanceTimeInForce::Gtc),
140 quantity: Some(quantity.into()),
141 quote_order_qty: None,
142 price: Some(price.into()),
143 new_client_order_id: None,
144 stop_price: None,
145 trailing_delta: None,
146 iceberg_qty: None,
147 new_order_resp_type: Some(BinanceOrderResponseType::Full),
148 self_trade_prevention_mode: None,
149 }
150 }
151
152 #[must_use]
154 pub fn market(
155 symbol: impl Into<String>,
156 side: BinanceSide,
157 quantity: impl Into<String>,
158 ) -> Self {
159 Self {
160 symbol: symbol.into(),
161 side,
162 order_type: BinanceSpotOrderType::Market,
163 time_in_force: None,
164 quantity: Some(quantity.into()),
165 quote_order_qty: None,
166 price: None,
167 new_client_order_id: None,
168 stop_price: None,
169 trailing_delta: None,
170 iceberg_qty: None,
171 new_order_resp_type: Some(BinanceOrderResponseType::Full),
172 self_trade_prevention_mode: None,
173 }
174 }
175
176 #[must_use]
178 pub fn with_client_order_id(mut self, id: impl Into<String>) -> Self {
179 self.new_client_order_id = Some(id.into());
180 self
181 }
182
183 #[must_use]
185 pub fn with_time_in_force(mut self, tif: BinanceTimeInForce) -> Self {
186 self.time_in_force = Some(tif);
187 self
188 }
189
190 #[must_use]
192 pub fn with_stop_price(mut self, price: impl Into<String>) -> Self {
193 self.stop_price = Some(price.into());
194 self
195 }
196
197 #[must_use]
199 pub fn with_stp_mode(mut self, mode: BinanceSelfTradePreventionMode) -> Self {
200 self.self_trade_prevention_mode = Some(mode);
201 self
202 }
203}
204
205#[derive(Debug, Clone, Serialize)]
207pub struct CancelOrderParams {
208 pub symbol: String,
210 #[serde(skip_serializing_if = "Option::is_none", rename = "orderId")]
212 pub order_id: Option<i64>,
213 #[serde(skip_serializing_if = "Option::is_none", rename = "origClientOrderId")]
215 pub orig_client_order_id: Option<String>,
216 #[serde(skip_serializing_if = "Option::is_none", rename = "newClientOrderId")]
218 pub new_client_order_id: Option<String>,
219}
220
221impl CancelOrderParams {
222 #[must_use]
224 pub fn by_order_id(symbol: impl Into<String>, order_id: i64) -> Self {
225 Self {
226 symbol: symbol.into(),
227 order_id: Some(order_id),
228 orig_client_order_id: None,
229 new_client_order_id: None,
230 }
231 }
232
233 #[must_use]
235 pub fn by_client_order_id(
236 symbol: impl Into<String>,
237 client_order_id: impl Into<String>,
238 ) -> Self {
239 Self {
240 symbol: symbol.into(),
241 order_id: None,
242 orig_client_order_id: Some(client_order_id.into()),
243 new_client_order_id: None,
244 }
245 }
246}
247
248#[derive(Debug, Clone, Serialize)]
250pub struct CancelOpenOrdersParams {
251 pub symbol: String,
253}
254
255impl CancelOpenOrdersParams {
256 #[must_use]
258 pub fn new(symbol: impl Into<String>) -> Self {
259 Self {
260 symbol: symbol.into(),
261 }
262 }
263}
264
265#[derive(Debug, Clone, Serialize)]
267pub struct CancelReplaceOrderParams {
268 pub symbol: String,
270 pub side: BinanceSide,
272 #[serde(rename = "type")]
274 pub order_type: BinanceSpotOrderType,
275 #[serde(rename = "cancelReplaceMode")]
277 pub cancel_replace_mode: BinanceCancelReplaceMode,
278 #[serde(skip_serializing_if = "Option::is_none", rename = "timeInForce")]
280 pub time_in_force: Option<BinanceTimeInForce>,
281 #[serde(skip_serializing_if = "Option::is_none")]
283 pub quantity: Option<String>,
284 #[serde(skip_serializing_if = "Option::is_none", rename = "quoteOrderQty")]
286 pub quote_order_qty: Option<String>,
287 #[serde(skip_serializing_if = "Option::is_none")]
289 pub price: Option<String>,
290 #[serde(skip_serializing_if = "Option::is_none", rename = "cancelOrderId")]
292 pub cancel_order_id: Option<i64>,
293 #[serde(
295 skip_serializing_if = "Option::is_none",
296 rename = "cancelOrigClientOrderId"
297 )]
298 pub cancel_orig_client_order_id: Option<String>,
299 #[serde(skip_serializing_if = "Option::is_none", rename = "newClientOrderId")]
301 pub new_client_order_id: Option<String>,
302 #[serde(skip_serializing_if = "Option::is_none", rename = "stopPrice")]
304 pub stop_price: Option<String>,
305 #[serde(skip_serializing_if = "Option::is_none", rename = "trailingDelta")]
307 pub trailing_delta: Option<i64>,
308 #[serde(skip_serializing_if = "Option::is_none", rename = "icebergQty")]
310 pub iceberg_qty: Option<String>,
311 #[serde(skip_serializing_if = "Option::is_none", rename = "newOrderRespType")]
313 pub new_order_resp_type: Option<BinanceOrderResponseType>,
314 #[serde(
316 skip_serializing_if = "Option::is_none",
317 rename = "selfTradePreventionMode"
318 )]
319 pub self_trade_prevention_mode: Option<BinanceSelfTradePreventionMode>,
320}
321
322#[derive(Debug, Clone, Serialize)]
324pub struct QueryOrderParams {
325 pub symbol: String,
327 #[serde(skip_serializing_if = "Option::is_none", rename = "orderId")]
329 pub order_id: Option<i64>,
330 #[serde(skip_serializing_if = "Option::is_none", rename = "origClientOrderId")]
332 pub orig_client_order_id: Option<String>,
333}
334
335impl QueryOrderParams {
336 #[must_use]
338 pub fn by_order_id(symbol: impl Into<String>, order_id: i64) -> Self {
339 Self {
340 symbol: symbol.into(),
341 order_id: Some(order_id),
342 orig_client_order_id: None,
343 }
344 }
345
346 #[must_use]
348 pub fn by_client_order_id(
349 symbol: impl Into<String>,
350 client_order_id: impl Into<String>,
351 ) -> Self {
352 Self {
353 symbol: symbol.into(),
354 order_id: None,
355 orig_client_order_id: Some(client_order_id.into()),
356 }
357 }
358}
359
360#[derive(Debug, Clone, Default, Serialize)]
362pub struct OpenOrdersParams {
363 #[serde(skip_serializing_if = "Option::is_none")]
365 pub symbol: Option<String>,
366}
367
368impl OpenOrdersParams {
369 #[must_use]
371 pub fn all() -> Self {
372 Self { symbol: None }
373 }
374
375 #[must_use]
377 pub fn for_symbol(symbol: impl Into<String>) -> Self {
378 Self {
379 symbol: Some(symbol.into()),
380 }
381 }
382}
383
384#[derive(Debug, Clone, Serialize)]
386pub struct AllOrdersParams {
387 pub symbol: String,
389 #[serde(skip_serializing_if = "Option::is_none", rename = "orderId")]
391 pub order_id: Option<i64>,
392 #[serde(skip_serializing_if = "Option::is_none", rename = "startTime")]
394 pub start_time: Option<i64>,
395 #[serde(skip_serializing_if = "Option::is_none", rename = "endTime")]
397 pub end_time: Option<i64>,
398 #[serde(skip_serializing_if = "Option::is_none")]
400 pub limit: Option<u32>,
401}
402
403impl AllOrdersParams {
404 #[must_use]
406 pub fn new(symbol: impl Into<String>) -> Self {
407 Self {
408 symbol: symbol.into(),
409 order_id: None,
410 start_time: None,
411 end_time: None,
412 limit: None,
413 }
414 }
415
416 #[must_use]
418 pub fn with_limit(mut self, limit: u32) -> Self {
419 self.limit = Some(limit);
420 self
421 }
422
423 #[must_use]
425 pub fn with_time_range(mut self, start: i64, end: i64) -> Self {
426 self.start_time = Some(start);
427 self.end_time = Some(end);
428 self
429 }
430}
431
432#[derive(Debug, Clone, Serialize)]
434pub struct NewOcoOrderParams {
435 pub symbol: String,
437 pub side: BinanceSide,
439 pub quantity: String,
441 pub price: String,
443 #[serde(rename = "stopPrice")]
445 pub stop_price: String,
446 #[serde(skip_serializing_if = "Option::is_none", rename = "stopLimitPrice")]
448 pub stop_limit_price: Option<String>,
449 #[serde(skip_serializing_if = "Option::is_none", rename = "listClientOrderId")]
451 pub list_client_order_id: Option<String>,
452 #[serde(skip_serializing_if = "Option::is_none", rename = "limitClientOrderId")]
454 pub limit_client_order_id: Option<String>,
455 #[serde(skip_serializing_if = "Option::is_none", rename = "stopClientOrderId")]
457 pub stop_client_order_id: Option<String>,
458 #[serde(skip_serializing_if = "Option::is_none", rename = "limitIcebergQty")]
460 pub limit_iceberg_qty: Option<String>,
461 #[serde(skip_serializing_if = "Option::is_none", rename = "stopIcebergQty")]
463 pub stop_iceberg_qty: Option<String>,
464 #[serde(
466 skip_serializing_if = "Option::is_none",
467 rename = "stopLimitTimeInForce"
468 )]
469 pub stop_limit_time_in_force: Option<BinanceTimeInForce>,
470 #[serde(skip_serializing_if = "Option::is_none", rename = "newOrderRespType")]
472 pub new_order_resp_type: Option<BinanceOrderResponseType>,
473 #[serde(
475 skip_serializing_if = "Option::is_none",
476 rename = "selfTradePreventionMode"
477 )]
478 pub self_trade_prevention_mode: Option<BinanceSelfTradePreventionMode>,
479}
480
481impl NewOcoOrderParams {
482 #[must_use]
484 pub fn new(
485 symbol: impl Into<String>,
486 side: BinanceSide,
487 quantity: impl Into<String>,
488 price: impl Into<String>,
489 stop_price: impl Into<String>,
490 ) -> Self {
491 Self {
492 symbol: symbol.into(),
493 side,
494 quantity: quantity.into(),
495 price: price.into(),
496 stop_price: stop_price.into(),
497 stop_limit_price: None,
498 list_client_order_id: None,
499 limit_client_order_id: None,
500 stop_client_order_id: None,
501 limit_iceberg_qty: None,
502 stop_iceberg_qty: None,
503 stop_limit_time_in_force: None,
504 new_order_resp_type: Some(BinanceOrderResponseType::Full),
505 self_trade_prevention_mode: None,
506 }
507 }
508
509 #[must_use]
511 pub fn with_stop_limit_price(mut self, price: impl Into<String>) -> Self {
512 self.stop_limit_price = Some(price.into());
513 self.stop_limit_time_in_force = Some(BinanceTimeInForce::Gtc);
514 self
515 }
516}
517
518#[derive(Debug, Clone, Serialize)]
520pub struct CancelOrderListParams {
521 pub symbol: String,
523 #[serde(skip_serializing_if = "Option::is_none", rename = "orderListId")]
525 pub order_list_id: Option<i64>,
526 #[serde(skip_serializing_if = "Option::is_none", rename = "listClientOrderId")]
528 pub list_client_order_id: Option<String>,
529 #[serde(skip_serializing_if = "Option::is_none", rename = "newClientOrderId")]
531 pub new_client_order_id: Option<String>,
532}
533
534impl CancelOrderListParams {
535 #[must_use]
537 pub fn by_order_list_id(symbol: impl Into<String>, order_list_id: i64) -> Self {
538 Self {
539 symbol: symbol.into(),
540 order_list_id: Some(order_list_id),
541 list_client_order_id: None,
542 new_client_order_id: None,
543 }
544 }
545
546 #[must_use]
548 pub fn by_list_client_order_id(
549 symbol: impl Into<String>,
550 list_client_order_id: impl Into<String>,
551 ) -> Self {
552 Self {
553 symbol: symbol.into(),
554 order_list_id: None,
555 list_client_order_id: Some(list_client_order_id.into()),
556 new_client_order_id: None,
557 }
558 }
559}
560
561#[derive(Debug, Clone, Serialize)]
563pub struct QueryOrderListParams {
564 #[serde(skip_serializing_if = "Option::is_none", rename = "orderListId")]
566 pub order_list_id: Option<i64>,
567 #[serde(skip_serializing_if = "Option::is_none", rename = "origClientOrderId")]
569 pub orig_client_order_id: Option<String>,
570}
571
572impl QueryOrderListParams {
573 #[must_use]
575 pub fn by_order_list_id(order_list_id: i64) -> Self {
576 Self {
577 order_list_id: Some(order_list_id),
578 orig_client_order_id: None,
579 }
580 }
581
582 #[must_use]
584 pub fn by_client_order_id(client_order_id: impl Into<String>) -> Self {
585 Self {
586 order_list_id: None,
587 orig_client_order_id: Some(client_order_id.into()),
588 }
589 }
590}
591
592#[derive(Debug, Clone, Default, Serialize)]
594pub struct AllOrderListsParams {
595 #[serde(skip_serializing_if = "Option::is_none", rename = "startTime")]
597 pub start_time: Option<i64>,
598 #[serde(skip_serializing_if = "Option::is_none", rename = "endTime")]
600 pub end_time: Option<i64>,
601 #[serde(skip_serializing_if = "Option::is_none")]
603 pub limit: Option<u32>,
604}
605
606#[derive(Debug, Clone, Default, Serialize)]
608pub struct OpenOrderListsParams {}
609
610#[derive(Debug, Clone, Default, Serialize)]
612pub struct AccountInfoParams {
613 #[serde(skip_serializing_if = "Option::is_none", rename = "omitZeroBalances")]
615 pub omit_zero_balances: Option<bool>,
616}
617
618impl AccountInfoParams {
619 #[must_use]
621 pub fn new() -> Self {
622 Self::default()
623 }
624
625 #[must_use]
627 pub fn omit_zero_balances(mut self) -> Self {
628 self.omit_zero_balances = Some(true);
629 self
630 }
631}
632
633#[derive(Debug, Clone, Serialize)]
635pub struct AccountTradesParams {
636 pub symbol: String,
638 #[serde(skip_serializing_if = "Option::is_none", rename = "orderId")]
640 pub order_id: Option<i64>,
641 #[serde(skip_serializing_if = "Option::is_none", rename = "startTime")]
643 pub start_time: Option<i64>,
644 #[serde(skip_serializing_if = "Option::is_none", rename = "endTime")]
646 pub end_time: Option<i64>,
647 #[serde(skip_serializing_if = "Option::is_none", rename = "fromId")]
649 pub from_id: Option<i64>,
650 #[serde(skip_serializing_if = "Option::is_none")]
652 pub limit: Option<u32>,
653}
654
655impl AccountTradesParams {
656 #[must_use]
658 pub fn new(symbol: impl Into<String>) -> Self {
659 Self {
660 symbol: symbol.into(),
661 order_id: None,
662 start_time: None,
663 end_time: None,
664 from_id: None,
665 limit: None,
666 }
667 }
668
669 #[must_use]
671 pub fn for_order(mut self, order_id: i64) -> Self {
672 self.order_id = Some(order_id);
673 self
674 }
675
676 #[must_use]
678 pub fn with_limit(mut self, limit: u32) -> Self {
679 self.limit = Some(limit);
680 self
681 }
682
683 #[must_use]
685 pub fn with_time_range(mut self, start: i64, end: i64) -> Self {
686 self.start_time = Some(start);
687 self.end_time = Some(end);
688 self
689 }
690}