Skip to main content

gateio_rs/api/spot/
get_insurance_history.rs

1use crate::http::{Credentials, Method, request::Request};
2
3/// Request for retrieving insurance history records
4pub struct GetInsuranceHistory {
5    /// Business type for insurance history query
6    pub business: String,
7    /// Currency to filter insurance records by
8    pub currency: String,
9    /// Start timestamp for the date range
10    pub from: i64,
11    /// End timestamp for the date range
12    pub to: i64,
13    /// Maximum number of records to return per page
14    pub limit: Option<u32>,
15    /// Page number for pagination
16    pub page: Option<u32>,
17    /// API credentials for authentication
18    pub credentials: Option<Credentials>,
19}
20
21impl GetInsuranceHistory {
22    /// Creates a new GetInsuranceHistory request with required parameters
23    pub fn new(business: &str, currency: &str, from: i64, to: i64) -> Self {
24        Self {
25            business: business.to_owned(),
26            currency: currency.to_owned(),
27            from,
28            to,
29            limit: None,
30            page: None,
31            credentials: None,
32        }
33    }
34
35    /// Sets the maximum number of records per page
36    pub fn limit(mut self, limit: u32) -> Self {
37        self.limit = Some(limit);
38        self
39    }
40
41    /// Sets the page number for pagination
42    pub fn page(mut self, page: u32) -> Self {
43        self.page = Some(page);
44        self
45    }
46
47    /// Sets the API credentials for authentication
48    pub fn credentials(mut self, creds: Credentials) -> Self {
49        self.credentials = Some(creds);
50        self
51    }
52}
53
54impl From<GetInsuranceHistory> for Request {
55    fn from(req: GetInsuranceHistory) -> Request {
56        let mut params = Vec::new();
57
58        params.push(("business".to_owned(), req.business));
59        params.push(("currency".to_owned(), req.currency));
60        params.push(("from".to_owned(), req.from.to_string()));
61        params.push(("to".to_owned(), req.to.to_string()));
62        if let Some(limit) = req.limit {
63            params.push(("limit".to_owned(), limit.to_string()));
64        }
65        if let Some(page) = req.page {
66            params.push(("page".to_owned(), page.to_string()));
67        }
68
69        Request {
70            method: Method::Get,
71            path: "/api/v4/spot/insurance_history".into(),
72            params,
73            payload: String::new(),
74            x_gate_exp_time: None,
75            credentials: req.credentials,
76            sign: true,
77        }
78    }
79}