gateio_rs/api/spot/
get_market_trades.rs1use crate::http::{Credentials, Method, request::Request};
2
3pub struct GetMarketTrades {
5 pub currency_pair: String,
7 pub limit: Option<i32>,
9 pub last_id: Option<String>,
11 pub reverse: Option<bool>,
13 pub from: Option<i64>,
15 pub to: Option<i64>,
17 pub page: Option<i32>,
19 pub credentials: Option<Credentials>,
21}
22
23impl GetMarketTrades {
24 pub fn new(currency_pair: &str) -> Self {
26 Self {
27 currency_pair: currency_pair.to_owned(),
28 limit: None,
29 last_id: None,
30 reverse: None,
31 from: None,
32 to: None,
33 page: None,
34 credentials: None,
35 }
36 }
37
38 pub fn limit(mut self, limit: i32) -> Self {
40 self.limit = Some(limit.into());
41 self
42 }
43
44 pub fn last_id(mut self, last_id: &str) -> Self {
46 self.last_id = Some(last_id.into());
47 self
48 }
49
50 pub fn reverse(mut self, reverse: bool) -> Self {
52 self.reverse = Some(reverse.into());
53 self
54 }
55
56 pub fn from(mut self, from: i64) -> Self {
58 self.from = Some(from.into());
59 self
60 }
61
62 pub fn to(mut self, to: i64) -> Self {
64 self.to = Some(to.into());
65 self
66 }
67
68 pub fn page(mut self, page: i32) -> Self {
70 self.page = Some(page.into());
71 self
72 }
73
74 pub fn credentials(mut self, creds: Credentials) -> Self {
76 self.credentials = Some(creds);
77 self
78 }
79}
80
81impl From<GetMarketTrades> for Request {
82 fn from(request: GetMarketTrades) -> Request {
83 let mut params = vec![("currency_pair".to_owned(), request.currency_pair)];
84
85 if let Some(limit) = request.limit {
86 params.push(("limit".into(), limit.to_string()));
87 }
88
89 if let Some(last_id) = request.last_id {
90 params.push(("last_id".into(), last_id.to_string()));
91 }
92
93 if let Some(reverse) = request.reverse {
94 params.push(("reverse".into(), reverse.to_string()));
95 }
96
97 if let Some(from) = request.from {
98 params.push(("from".into(), from.to_string()));
99 }
100
101 if let Some(to) = request.to {
102 params.push(("to".into(), to.to_string()));
103 }
104
105 if let Some(page) = request.page {
106 params.push(("page".into(), page.to_string()));
107 }
108
109 Request {
110 method: Method::Get,
111 path: "/api/v4/spot/trades".into(),
112 params,
113 payload: "".to_string(),
114 x_gate_exp_time: None,
115 credentials: request.credentials,
116 sign: false,
117 }
118 }
119}