Skip to main content

gateio_rs/api/spot/
get_account.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving spot account information
4pub struct GetAccount {
5    /// Optional currency filter to get balances for a specific currency
6    pub currency: Option<String>,
7    /// API credentials for authentication
8    pub credentials: Option<Credentials>,
9}
10
11impl GetAccount {
12    /// Creates a new GetAccount request
13    pub fn new() -> Self {
14        Self {
15            currency: None,
16            credentials: None,
17        }
18    }
19
20    /// Sets the currency filter for the account query
21    pub fn currency(mut self, currency: &str) -> Self {
22        self.currency = Some(currency.into());
23        self
24    }
25
26    /// Sets the API credentials for authentication
27    pub fn credentials(mut self, creds: Credentials) -> Self {
28        self.credentials = Some(creds);
29        self
30    }
31}
32
33impl From<GetAccount> for Request {
34    fn from(request: GetAccount) -> Request {
35        let mut params = Vec::new();
36        if let Some(currency) = request.currency {
37            params.push(("currency".into(), currency));
38        }
39
40        Request {
41            method: Method::Get,
42            path: "/api/v4/spot/accounts".into(),
43            params,
44            payload: "".to_string(),
45            x_gate_exp_time: None,
46            credentials: request.credentials,
47            sign: true,
48        }
49    }
50}