binance_client/http_api_v3/data/order/delete/
request.rs

1//!
2//! The order DELETE request.
3//!
4
5use chrono::prelude::*;
6
7///
8/// The `https://www.binance.com/api/v3/order` POST request query.
9///
10pub struct Query {
11    /// The symbol name.
12    pub symbol: String,
13    /// The order ID to cancel.
14    pub order_id: Option<i64>,
15    /// Either `orderId` or `origClientOrderId` must be sent.
16    pub orig_client_order_id: Option<String>,
17    /// Used to uniquely identify this cancel. Automatically generated by default.
18    pub new_client_order_id: Option<String>,
19    /// The allowed time window between the request and response in milliseconds.
20    pub recv_window: Option<i64>,
21    /// The request time in milliseconds.
22    pub timestamp: i64,
23}
24
25impl Query {
26    /// The query params default capacity.
27    const QUERY_INITIAL_CAPACITY: usize = 256;
28
29    ///
30    /// A shortcut constructor.
31    ///
32    pub fn new(symbol: &str, orig_client_order_id: &str) -> Self {
33        Self {
34            symbol: symbol.to_owned(),
35            order_id: None,
36            orig_client_order_id: Some(orig_client_order_id.to_owned()),
37            new_client_order_id: None,
38            recv_window: None,
39            timestamp: Utc::now().timestamp_millis(),
40        }
41    }
42}
43
44impl ToString for Query {
45    fn to_string(&self) -> String {
46        let mut params = String::with_capacity(Self::QUERY_INITIAL_CAPACITY);
47        params += &format!("symbol={}", self.symbol.to_owned());
48        if let Some(order_id) = self.order_id {
49            params += &format!("&orderId={}", order_id);
50        }
51        if let Some(ref orig_client_order_id) = self.orig_client_order_id {
52            params += &format!("&origClientOrderId={}", orig_client_order_id.to_owned());
53        }
54        if let Some(ref new_client_order_id) = self.new_client_order_id {
55            params += &format!("&newClientOrderId={}", new_client_order_id.to_owned());
56        }
57        if let Some(recv_window) = self.recv_window {
58            params += &format!("&recvWindow={}", recv_window);
59        }
60        params += &format!("&timestamp={}", self.timestamp);
61        params
62    }
63}