Skip to main content

gateio_rs/api/spot/
get_open_orders.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving all open orders
4pub struct GetOpenOrders {
5    /// Page number for pagination
6    pub page: Option<i32>,
7    /// Maximum number of orders to return per page
8    pub limit: Option<i32>,
9    /// Optional account type filter
10    pub account: Option<String>,
11    /// API credentials for authentication
12    pub credentials: Option<Credentials>,
13}
14
15impl GetOpenOrders {
16    /// Creates a new GetOpenOrders request
17    pub fn new() -> Self {
18        Self {
19            page: None,
20            limit: None,
21            account: None,
22            credentials: None,
23        }
24    }
25
26    /// Sets the page number for pagination
27    pub fn page(mut self, page: i32) -> Self {
28        self.page = Some(page);
29        self
30    }
31
32    /// Sets the maximum number of orders per page
33    pub fn limit(mut self, limit: i32) -> Self {
34        self.limit = Some(limit);
35        self
36    }
37
38    /// Sets the account type filter
39    pub fn account(mut self, account: &str) -> Self {
40        self.account = Some(account.into());
41        self
42    }
43
44    /// Sets the API credentials for authentication
45    pub fn credentials(mut self, creds: Credentials) -> Self {
46        self.credentials = Some(creds);
47        self
48    }
49}
50
51impl From<GetOpenOrders> for Request {
52    fn from(request: GetOpenOrders) -> Request {
53        let mut params = Vec::new();
54
55        if let Some(page) = request.page {
56            params.push(("page".into(), page.to_string()));
57        }
58
59        if let Some(limit) = request.limit {
60            params.push(("limit".into(), limit.to_string()));
61        }
62
63        if let Some(account) = request.account {
64            params.push(("account".into(), account));
65        }
66
67        Request {
68            method: Method::Get,
69            path: "/api/v4/spot/open_orders".into(),
70            params,
71            payload: "".to_string(),
72            x_gate_exp_time: None,
73            credentials: request.credentials,
74            sign: true,
75        }
76    }
77}