Skip to main content

datamaxi/
models.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4/// Detailed information about a candle.
5#[derive(Serialize, Deserialize, Debug)]
6pub struct CandleDetail {
7    /// The timestamp of the candle's open time.
8    #[serde(rename = "d")]
9    pub timestamp: String,
10
11    /// The opening price of the asset at the beginning of the time frame.
12    #[serde(rename = "o")]
13    pub open: String,
14
15    /// The highest price of the asset during the time frame.
16    #[serde(rename = "h")]
17    pub high: String,
18
19    /// The lowest price of the asset during the time frame.
20    #[serde(rename = "l")]
21    pub low: String,
22
23    /// The closing price of the asset at the end of the time frame.
24    #[serde(rename = "c")]
25    pub close: String,
26
27    /// The total volume of trades (in the base currency) that occurred during the time frame.
28    #[serde(rename = "v")]
29    pub volume: String,
30}
31
32/// Response containing candle data.
33#[derive(Serialize, Deserialize, Debug)]
34pub struct CandleResponse {
35    /// A vector containing detailed information about each candle.
36    pub data: Vec<CandleDetail>,
37
38    /// The current page number in the paginated response.
39    pub page: i32,
40
41    /// The maximum number of items per page in the response.
42    pub limit: i32,
43
44    /// The starting point of the time frame for the candle data.
45    pub from: String,
46
47    /// The ending point of the time frame for the candle data.
48    pub to: String,
49
50    /// The sorting order for the candle data (e.g., "asc" or "desc").
51    pub sort: String,
52}
53
54/// Detailed information about a trade.
55#[derive(Serialize, Deserialize, Debug)]
56pub struct TradeDetail {
57    /// The timestamp of the trade.
58    #[serde(rename = "d")]
59    pub timestamp: String,
60
61    /// The block number in which the trade was recorded.
62    #[serde(rename = "b")]
63    pub block_number: i64,
64
65    /// The trading pool where the trade occurred.
66    #[serde(rename = "pool")]
67    pub pool: String,
68
69    /// The trading symbol associated with the trade (e.g., BTC-USDT).
70    #[serde(rename = "s")]
71    pub symbol: String,
72
73    /// The hash of the transaction related to the trade.
74    #[serde(rename = "tx")]
75    pub transaction_hash: String,
76
77    /// The maker of the trade (the party who placed the order).
78    #[serde(rename = "m")]
79    pub maker: String,
80
81    /// The type of trade (e.g., buy or sell).
82    #[serde(rename = "t")]
83    pub trade_type: String,
84
85    /// The quantity of the base asset traded, in base unit.
86    #[serde(rename = "bq")]
87    pub base_quantity: String,
88
89    /// The quantity of the quote asset traded, in base unit.
90    #[serde(rename = "qq")]
91    pub quote_quantity: String,
92
93    /// The price of the trade in the quote asset's unit.
94    #[serde(rename = "p")]
95    pub price: String,
96}
97
98/// Response containing trade data.
99#[derive(Serialize, Deserialize, Debug)]
100pub struct TradeResponse {
101    /// A vector containing detailed information about each trade.
102    pub data: Vec<TradeDetail>,
103
104    /// The current page number in the paginated response.
105    pub page: i32,
106
107    /// The maximum number of items per page in the response.
108    pub limit: i32,
109
110    /// The starting point of the time frame for the trade data.
111    pub from: String,
112
113    /// The ending point of the time frame for the trade data.
114    pub to: String,
115
116    /// The sorting order for the trade data (e.g., "asc" or "desc").
117    pub sort: String,
118}
119
120/// Optional parameters for a candle request.
121pub struct CandleOptions {
122    /// The market type (e.g., spot, futures).
123    pub market: Option<String>,
124
125    /// The interval for the candle data (e.g., 1m, 1h, 1d).
126    pub interval: Option<String>,
127
128    /// The page number for the candle data.
129    pub page: Option<i32>,
130
131    /// The maximum number of items per page in the response.
132    pub limit: Option<i32>,
133
134    /// The starting date & time for the candle data.
135    pub from: Option<String>,
136
137    /// The ending date & time for the candle data.
138    pub to: Option<String>,
139
140    /// The sorting order for the candle data (e.g., "asc" or "desc").
141    pub sort: Option<String>,
142}
143
144impl Default for CandleOptions {
145    fn default() -> Self {
146        Self::new()
147    }
148}
149
150/// Provides a builder pattern for setting optional parameters for a candle request.
151impl CandleOptions {
152    /// Creates a new instance of `CandleOptions` with default values.
153    pub fn new() -> Self {
154        CandleOptions {
155            market: None,
156            interval: None,
157            page: 1.into(),
158            limit: 1000.into(),
159            from: None,
160            to: None,
161            sort: Some("desc".into()),
162        }
163    }
164
165    /// Sets the market for the candle query.
166    pub fn market(mut self, market: &str) -> Self {
167        self.market = Some(market.into());
168        self
169    }
170
171    /// Sets the interval for the candle query.
172    pub fn interval(mut self, interval: &str) -> Self {
173        self.interval = Some(interval.into());
174        self
175    }
176
177    /// Sets the page number for the candle query.
178    pub fn page(mut self, page: i32) -> Self {
179        self.page = Some(page);
180        self
181    }
182
183    /// Sets the limit for the number of results returned.
184    pub fn limit(mut self, limit: i32) -> Self {
185        self.limit = Some(limit);
186        self
187    }
188
189    /// Sets the starting date & time for the candle query.
190    pub fn from(mut self, from: &str) -> Self {
191        self.from = Some(from.into());
192        self
193    }
194
195    /// Sets the ending date & time for the candle query.
196    pub fn to(mut self, to: &str) -> Self {
197        self.to = Some(to.into());
198        self
199    }
200
201    /// Sets the sort order for the candle query (e.g., "asc" or "desc").
202    pub fn sort(mut self, sort: &str) -> Self {
203        self.sort = Some(sort.into());
204        self
205    }
206}
207
208/// Response containing details about symbols.
209#[derive(Serialize, Deserialize, Debug)]
210pub struct SymbolsResponse {
211    /// The name of the exchange.
212    #[serde(rename = "e")]
213    pub exchange: String,
214
215    /// The market type (e.g., spot, futures).
216    #[serde(rename = "m")]
217    pub market: String,
218
219    /// The base asset of the trading pair.
220    #[serde(rename = "b")]
221    pub base: String,
222
223    /// The quote asset of the trading pair.
224    #[serde(rename = "q")]
225    pub quote: String,
226
227    /// The trading symbol (e.g., BTC-USDT).
228    #[serde(rename = "s")]
229    pub symbol: String,
230
231    /// An optional unique identifier for the symbol.
232    #[serde(rename = "id")]
233    pub id: Option<String>,
234}
235
236/// Optional parameters for a symbols request.
237pub struct SymbolsOptions {
238    /// The market type (e.g., spot, futures).
239    pub market: Option<String>,
240}
241
242impl Default for SymbolsOptions {
243    fn default() -> Self {
244        Self::new()
245    }
246}
247
248impl SymbolsOptions {
249    /// Creates a new instance of `SymbolsOptions` with default values.
250    pub fn new() -> Self {
251        SymbolsOptions { market: None }
252    }
253
254    /// Sets the market for the symbols query.
255    pub fn market(mut self, market: &str) -> Self {
256        self.market = Some(market.into());
257        self
258    }
259}
260
261/// Response containing details about pools.
262#[derive(Serialize, Deserialize, Debug)]
263pub struct PoolsResponse {
264    /// The blockchain where the pool is located.
265    #[serde(rename = "c")]
266    pub chain: String,
267
268    /// The name of the exchange where the pool is available.
269    #[serde(rename = "e")]
270    pub exchange: String,
271
272    /// The base asset used in the pool.
273    #[serde(rename = "b")]
274    pub base: String,
275
276    /// The quote asset used in the pool.
277    #[serde(rename = "q")]
278    pub quote: String,
279
280    /// The address of the base token in the pool.
281    #[serde(rename = "ba")]
282    pub baset_address: String,
283
284    /// The address of the quote token in the pool.
285    #[serde(rename = "qa")]
286    pub quote_address: String,
287
288    /// The unique address of the pool.
289    #[serde(rename = "pa")]
290    pub pool_address: String,
291
292    /// An optional unique identifier for the pool.
293    #[serde(rename = "id")]
294    pub id: Option<String>,
295}
296
297/// Optional parameters for a trade request.
298pub struct TradeOptions {
299    /// The page number for the trade query.
300    pub page: Option<i32>,
301
302    /// The maximum number of items per page in the response.
303    pub limit: Option<i32>,
304
305    /// The starting date for the trade query.
306    pub from: Option<String>,
307
308    /// The ending date for the trade query.
309    pub to: Option<String>,
310
311    /// The sorting order for the trade query (e.g., "asc" or "desc").
312    pub sort: Option<String>,
313}
314
315impl Default for TradeOptions {
316    fn default() -> Self {
317        Self::new()
318    }
319}
320
321/// Provides a builder pattern for setting optional parameters for a trade.
322impl TradeOptions {
323    /// Creates a new instance of `TradeOptions` with default values.
324    pub fn new() -> Self {
325        TradeOptions {
326            page: 1.into(),
327            limit: 1000.into(),
328            from: None,
329            to: None,
330            sort: Some("desc".into()),
331        }
332    }
333
334    /// Sets the page number for the trade query.
335    pub fn page(mut self, page: i32) -> Self {
336        self.page = Some(page);
337        self
338    }
339
340    /// Sets the limit for the number of results returned.
341    pub fn limit(mut self, limit: i32) -> Self {
342        self.limit = Some(limit);
343        self
344    }
345
346    /// Sets the starting date for the trade query.
347    pub fn from(mut self, from: &str) -> Self {
348        self.from = Some(from.into());
349        self
350    }
351
352    /// Sets the ending date for the trade query.
353    pub fn to(mut self, to: &str) -> Self {
354        self.to = Some(to.into());
355        self
356    }
357
358    /// Sets the sort order for the trade query (e.g., "asc" or "desc").
359    pub fn sort(mut self, sort: &str) -> Self {
360        self.sort = Some(sort.into());
361        self
362    }
363}
364
365/// Optional parameters for a pools request.
366pub struct PoolsOptions {
367    /// The chain for the pools query.
368    pub chain: Option<String>,
369
370    /// The exchange for the pools query.
371    pub exchange: Option<String>,
372}
373
374impl Default for PoolsOptions {
375    fn default() -> Self {
376        Self::new()
377    }
378}
379
380/// Provides a builder pattern for setting optional parameters for a pools request.
381impl PoolsOptions {
382    /// Creates a new instance of `PoolsOptions` with default values.
383    pub fn new() -> Self {
384        PoolsOptions {
385            chain: None,
386            exchange: None,
387        }
388    }
389
390    /// Sets the chain for the pools query.
391    pub fn chain(mut self, chain: &str) -> Self {
392        self.chain = Some(chain.into());
393        self
394    }
395
396    /// Sets the exchange for the pools query.
397    pub fn exchange(mut self, exchange: &str) -> Self {
398        self.exchange = Some(exchange.into());
399        self
400    }
401}