binance_spot_connector_rust/trade/
get_oco_order.rs

1use crate::http::{request::Request, Credentials, Method};
2
3/// `GET /api/v3/orderList`
4///
5/// Retrieves a specific OCO based on provided optional parameters
6///
7/// Weight(IP): 4
8///
9/// # Example
10///
11/// ```
12/// use binance_spot_connector_rust::trade;
13///
14/// let request = trade::get_oco_order().order_list_id(11);
15/// ```
16pub struct GetOCOOrder {
17    order_list_id: Option<u64>,
18    orig_client_order_id: Option<String>,
19    recv_window: Option<u64>,
20    credentials: Option<Credentials>,
21}
22
23impl GetOCOOrder {
24    pub fn new() -> Self {
25        Self {
26            order_list_id: None,
27            orig_client_order_id: None,
28            recv_window: None,
29            credentials: None,
30        }
31    }
32
33    pub fn order_list_id(mut self, order_list_id: u64) -> Self {
34        self.order_list_id = Some(order_list_id);
35        self
36    }
37
38    pub fn orig_client_order_id(mut self, orig_client_order_id: &str) -> Self {
39        self.orig_client_order_id = Some(orig_client_order_id.to_owned());
40        self
41    }
42
43    pub fn recv_window(mut self, recv_window: u64) -> Self {
44        self.recv_window = Some(recv_window);
45        self
46    }
47
48    pub fn credentials(mut self, credentials: &Credentials) -> Self {
49        self.credentials = Some(credentials.clone());
50        self
51    }
52}
53
54impl From<GetOCOOrder> for Request {
55    fn from(request: GetOCOOrder) -> Request {
56        let mut params = vec![];
57
58        if let Some(order_list_id) = request.order_list_id {
59            params.push(("orderListId".to_owned(), order_list_id.to_string()));
60        }
61
62        if let Some(orig_client_order_id) = request.orig_client_order_id {
63            params.push(("origClientOrderId".to_owned(), orig_client_order_id));
64        }
65
66        if let Some(recv_window) = request.recv_window {
67            params.push(("recvWindow".to_owned(), recv_window.to_string()));
68        }
69
70        Request {
71            path: "/api/v3/orderList".to_owned(),
72            method: Method::Get,
73            params,
74            credentials: request.credentials,
75            sign: true,
76        }
77    }
78}
79
80impl Default for GetOCOOrder {
81    fn default() -> Self {
82        Self::new()
83    }
84}
85
86#[cfg(test)]
87mod tests {
88    use super::GetOCOOrder;
89    use crate::http::{request::Request, Credentials, Method};
90
91    static API_KEY: &str = "api-key";
92    static API_SECRET: &str = "api-secret";
93
94    #[test]
95    fn trade_get_oco_order_convert_to_request_test() {
96        let credentials = Credentials::from_hmac(API_KEY.to_owned(), API_SECRET.to_owned());
97
98        let request: Request = GetOCOOrder::new()
99            .order_list_id(11)
100            .recv_window(5000)
101            .credentials(&credentials)
102            .into();
103
104        assert_eq!(
105            request,
106            Request {
107                path: "/api/v3/orderList".to_owned(),
108                credentials: Some(credentials),
109                method: Method::Get,
110                params: vec![
111                    ("orderListId".to_owned(), "11".to_string()),
112                    ("recvWindow".to_owned(), "5000".to_string()),
113                ],
114                sign: true
115            }
116        );
117    }
118}