Skip to main content

gateio_rs/api/spot/
get_orders.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving order history with various filtering options
4pub struct GetOrders {
5    /// Optional currency pair filter for orders
6    pub currency_pair: Option<String>,
7    /// Order status filter ("open", "closed", "cancelled")
8    pub status: Option<String>,
9    /// Page number for pagination
10    pub page: Option<i32>,
11    /// Maximum number of orders to return per page
12    pub limit: Option<i32>,
13    /// Optional account type filter
14    pub account: Option<String>,
15    /// Start timestamp for order history range
16    pub from: Option<i64>,
17    /// End timestamp for order history range
18    pub to: Option<i64>,
19    /// Order side filter ("buy" or "sell")
20    pub side: Option<String>,
21    /// API credentials for authentication
22    pub credentials: Option<Credentials>,
23}
24
25impl GetOrders {
26    /// Creates a new GetOrders request
27    pub fn new() -> Self {
28        Self {
29            currency_pair: None,
30            status: None,
31            page: None,
32            limit: None,
33            account: None,
34            from: None,
35            to: None,
36            side: None,
37            credentials: None,
38        }
39    }
40
41    /// Sets the currency pair filter for orders
42    pub fn currency_pair(mut self, currency_pair: &str) -> Self {
43        self.currency_pair = Some(currency_pair.into());
44        self
45    }
46
47    /// Sets the order status filter
48    pub fn status(mut self, status: &str) -> Self {
49        self.status = Some(status.into());
50        self
51    }
52
53    /// Sets the page number for pagination
54    pub fn page(mut self, page: i32) -> Self {
55        self.page = Some(page);
56        self
57    }
58
59    /// Sets the maximum number of orders per page
60    pub fn limit(mut self, limit: i32) -> Self {
61        self.limit = Some(limit);
62        self
63    }
64
65    /// Sets the account type filter
66    pub fn account(mut self, account: &str) -> Self {
67        self.account = Some(account.into());
68        self
69    }
70
71    /// Sets the start timestamp for order history range
72    pub fn from(mut self, from: i64) -> Self {
73        self.from = Some(from);
74        self
75    }
76
77    /// Sets the end timestamp for order history range
78    pub fn to(mut self, to: i64) -> Self {
79        self.to = Some(to);
80        self
81    }
82
83    /// Sets the order side filter ("buy" or "sell")
84    pub fn side(mut self, side: &str) -> Self {
85        self.side = Some(side.into());
86        self
87    }
88
89    /// Sets the API credentials for authentication
90    pub fn credentials(mut self, creds: Credentials) -> Self {
91        self.credentials = Some(creds);
92        self
93    }
94}
95
96impl From<GetOrders> for Request {
97    fn from(request: GetOrders) -> Request {
98        let mut params = Vec::new();
99
100        if let Some(currency_pair) = request.currency_pair {
101            params.push(("currency_pair".into(), currency_pair));
102        }
103
104        if let Some(status) = request.status {
105            params.push(("status".into(), status));
106        }
107
108        if let Some(page) = request.page {
109            params.push(("page".into(), page.to_string()));
110        }
111
112        if let Some(limit) = request.limit {
113            params.push(("limit".into(), limit.to_string()));
114        }
115
116        if let Some(account) = request.account {
117            params.push(("account".into(), account));
118        }
119
120        if let Some(from) = request.from {
121            params.push(("from".into(), from.to_string()));
122        }
123
124        if let Some(to) = request.to {
125            params.push(("to".into(), to.to_string()));
126        }
127
128        if let Some(side) = request.side {
129            params.push(("side".into(), side));
130        }
131
132        Request {
133            method: Method::Get,
134            path: "/api/v4/spot/orders".into(),
135            params,
136            payload: "".to_string(),
137            x_gate_exp_time: None,
138            credentials: request.credentials,
139            sign: true,
140        }
141    }
142}