gateio_rs/api/spot/
get_candlesticks.rs1use crate::http::{Credentials, Method, request::Request};
2
3pub struct GetCandlesticks {
5 pub currency_pair: String,
7 pub limit: Option<i64>,
9 pub from: Option<i64>,
11 pub to: Option<i64>,
13 pub interval: Option<String>,
15 pub credentials: Option<Credentials>,
17}
18
19impl GetCandlesticks {
20 pub fn new(currency_pair: &str) -> Self {
22 Self {
23 currency_pair: currency_pair.to_owned(),
24 limit: None,
25 from: None,
26 to: None,
27 interval: None,
28 credentials: None,
29 }
30 }
31
32 pub fn limit(mut self, limit: i64) -> Self {
34 self.limit = Some(limit.into());
35 self
36 }
37
38 pub fn from(mut self, from: i64) -> Self {
40 self.from = Some(from.into());
41 self
42 }
43
44 pub fn to(mut self, to: i64) -> Self {
46 self.to = Some(to.into());
47 self
48 }
49
50 pub fn interval(mut self, interval: &str) -> Self {
52 self.interval = Some(interval.into());
53 self
54 }
55
56 pub fn credentials(mut self, creds: Credentials) -> Self {
58 self.credentials = Some(creds);
59 self
60 }
61}
62
63impl From<GetCandlesticks> for Request {
64 fn from(request: GetCandlesticks) -> Request {
65 let mut params = vec![("currency_pair".to_owned(), request.currency_pair)];
66
67 if let Some(limit) = request.limit {
68 params.push(("limit".into(), limit.to_string()));
69 }
70
71 if let Some(from) = request.from {
72 params.push(("from".into(), from.to_string()));
73 }
74
75 if let Some(to) = request.to {
76 params.push(("to".into(), to.to_string()));
77 }
78
79 if let Some(interval) = request.interval {
80 params.push(("interval".into(), interval.to_string()));
81 }
82
83 Request {
84 method: Method::Get,
85 path: "/api/v4/spot/candlesticks".into(),
86 params,
87 payload: "".to_string(),
88 x_gate_exp_time: None,
89 credentials: request.credentials,
90 sign: false,
91 }
92 }
93}