Skip to main content

gateio_rs/api/spot/
get_order.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving details of a specific order
4pub struct GetOrder {
5    /// Order ID to retrieve details for
6    pub order_id: String,
7    /// Currency pair the order belongs to
8    pub currency_pair: String,
9    /// Optional account type filter
10    pub account: Option<String>,
11    /// API credentials for authentication
12    pub credentials: Option<Credentials>,
13}
14
15impl GetOrder {
16    /// Creates a new GetOrder request with order ID and currency pair
17    pub fn new(order_id: &str, currency_pair: &str) -> Self {
18        Self {
19            order_id: order_id.into(),
20            currency_pair: currency_pair.into(),
21            account: None,
22            credentials: None,
23        }
24    }
25
26    /// Sets the account type filter
27    pub fn account(mut self, account: &str) -> Self {
28        self.account = Some(account.into());
29        self
30    }
31
32    /// Sets the API credentials for authentication
33    pub fn credentials(mut self, creds: Credentials) -> Self {
34        self.credentials = Some(creds);
35        self
36    }
37}
38
39impl From<GetOrder> for Request {
40    fn from(request: GetOrder) -> Request {
41        let mut params = Vec::new();
42
43        params.push(("currency_pair".into(), request.currency_pair));
44
45        if let Some(account) = request.account {
46            params.push(("account".into(), account));
47        }
48
49        Request {
50            method: Method::Get,
51            path: format!("/api/v4/spot/orders/{}", request.order_id),
52            params,
53            payload: "".to_string(),
54            x_gate_exp_time: None,
55            credentials: request.credentials,
56            sign: true,
57        }
58    }
59}