Skip to main content

gateio_rs/api/spot/
cancel_all_open_orders.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Cancel all open orders request
4pub struct CancelAllOpenOrders {
5    /// Trading pair filter
6    pub currency_pair: Option<String>,
7    /// API credentials
8    pub credentials: Option<Credentials>,
9}
10
11impl CancelAllOpenOrders {
12    /// Create cancel all request
13    pub fn new() -> Self {
14        Self {
15            currency_pair: None,
16            credentials: None,
17        }
18    }
19
20    /// Filter by trading pair
21    pub fn currency_pair(mut self, currency_pair: &str) -> Self {
22        self.currency_pair = Some(currency_pair.to_string());
23        self
24    }
25
26    /// Set API credentials
27    pub fn credentials(mut self, creds: Credentials) -> Self {
28        self.credentials = Some(creds);
29        self
30    }
31}
32
33impl From<CancelAllOpenOrders> for Request {
34    fn from(request: CancelAllOpenOrders) -> Request {
35        let mut params = Vec::new();
36
37        if let Some(currency_pair) = &request.currency_pair {
38            params.push(("currency_pair".to_string(), currency_pair.clone()));
39        }
40
41        Request {
42            method: Method::Delete,
43            path: "/api/v4/spot/orders".into(),
44            params,
45            payload: "".to_string(),
46            x_gate_exp_time: None,
47            credentials: request.credentials,
48            sign: true,
49        }
50    }
51}