Skip to main content

gateio_rs/api/spot/
get_my_trades.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving user's personal trading history
4pub struct GetMyTrades {
5    /// Optional currency pair filter for trades
6    pub currency_pair: Option<String>,
7    /// Page number for pagination
8    pub page: Option<i32>,
9    /// Maximum number of trades to return per page
10    pub limit: Option<i32>,
11    /// Start timestamp for trade history range
12    pub from: Option<i64>,
13    /// End timestamp for trade history range
14    pub to: Option<i64>,
15    /// Optional order ID to filter trades by
16    pub order_id: Option<String>,
17    /// API credentials for authentication
18    pub credentials: Option<Credentials>,
19}
20
21impl GetMyTrades {
22    /// Creates a new GetMyTrades request
23    pub fn new() -> Self {
24        Self {
25            currency_pair: None,
26            page: None,
27            limit: None,
28            from: None,
29            to: None,
30            order_id: None,
31            credentials: None,
32        }
33    }
34
35    /// Sets the currency pair filter for trades
36    pub fn currency_pair(mut self, currency_pair: &str) -> Self {
37        self.currency_pair = Some(currency_pair.into());
38        self
39    }
40
41    /// Sets the page number for pagination
42    pub fn page(mut self, page: i32) -> Self {
43        self.page = Some(page);
44        self
45    }
46
47    /// Sets the maximum number of trades per page
48    pub fn limit(mut self, limit: i32) -> Self {
49        self.limit = Some(limit);
50        self
51    }
52
53    /// Sets the start timestamp for trade history range
54    pub fn from(mut self, from: i64) -> Self {
55        self.from = Some(from);
56        self
57    }
58
59    /// Sets the end timestamp for trade history range
60    pub fn to(mut self, to: i64) -> Self {
61        self.to = Some(to);
62        self
63    }
64
65    /// Sets the order ID filter for trades
66    pub fn order_id(mut self, order_id: &str) -> Self {
67        self.order_id = Some(order_id.into());
68        self
69    }
70
71    /// Sets the API credentials for authentication
72    pub fn credentials(mut self, creds: Credentials) -> Self {
73        self.credentials = Some(creds);
74        self
75    }
76}
77
78impl From<GetMyTrades> for Request {
79    fn from(request: GetMyTrades) -> Request {
80        let mut params = Vec::new();
81
82        if let Some(currency_pair) = request.currency_pair {
83            params.push(("currency_pair".into(), currency_pair));
84        }
85
86        if let Some(page) = request.page {
87            params.push(("page".into(), page.to_string()));
88        }
89
90        if let Some(limit) = request.limit {
91            params.push(("limit".into(), limit.to_string()));
92        }
93
94        if let Some(from) = request.from {
95            params.push(("from".into(), from.to_string()));
96        }
97
98        if let Some(to) = request.to {
99            params.push(("to".into(), to.to_string()));
100        }
101
102        if let Some(order_id) = request.order_id {
103            params.push(("order_id".into(), order_id));
104        }
105
106        Request {
107            method: Method::Get,
108            path: "/api/v4/spot/my_trades".into(),
109            params,
110            payload: "".to_string(),
111            x_gate_exp_time: None,
112            credentials: request.credentials,
113            sign: true,
114        }
115    }
116}