Skip to main content

gateio_rs/api/spot/
get_account_book.rs

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