binance_client/http_api_v3/data/klines/get/
request.rs

1//!
2//! The klines GET request.
3//!
4
5use crate::http_api_v3::data::interval::Interval;
6
7///
8/// The `https://www.binance.com/api/v3/klines` GET request query.
9///
10pub struct Query {
11    /// The symbol name.
12    pub symbol: String,
13    /// The timeframe interval.
14    pub interval: Interval,
15    /// The left time boundary of the requested klines.
16    pub start_time: Option<i64>,
17    /// The right time boundary of the requested klines.
18    pub end_time: Option<i64>,
19    /// The maximum number of klines to get.
20    pub limit: Option<usize>,
21}
22
23impl Query {
24    /// The query params default capacity.
25    const QUERY_INITIAL_CAPACITY: usize = 128;
26
27    ///
28    /// A shortcut constructor.
29    ///
30    pub fn new(
31        symbol: String,
32        interval: Interval,
33        start_time: Option<i64>,
34        end_time: Option<i64>,
35        limit: Option<usize>,
36    ) -> Self {
37        Self {
38            symbol,
39            interval,
40            start_time,
41            end_time,
42            limit,
43        }
44    }
45}
46
47impl ToString for Query {
48    fn to_string(&self) -> String {
49        let mut params = String::with_capacity(Self::QUERY_INITIAL_CAPACITY);
50        params += &format!("symbol={}", self.symbol.to_owned());
51        params += &format!("&interval={}", self.interval);
52        if let Some(start_time) = self.start_time {
53            params += &format!("&startTime={}", start_time);
54        }
55        if let Some(end_time) = self.end_time {
56            params += &format!("&endTime={}", end_time);
57        }
58        if let Some(limit) = self.limit {
59            params += &format!("&limit={}", limit);
60        }
61        params
62    }
63}