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

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