1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//!
//! The klines GET request.
//!

use crate::data::Interval;

pub struct Request {
    symbol: String,
    interval: Interval,
    start_time: Option<i64>,
    end_time: Option<i64>,
    limit: Option<usize>,
}

impl Request {
    pub fn new(
        symbol: String,
        interval: Interval,
        start_time: Option<i64>,
        end_time: Option<i64>,
        limit: Option<usize>,
    ) -> Self {
        Self {
            symbol,
            interval,
            start_time,
            end_time,
            limit,
        }
    }
}

impl ToString for Request {
    fn to_string(&self) -> String {
        let mut params = String::with_capacity(128);
        params += &format!("symbol={}", self.symbol.to_owned());
        params += &format!("&interval={}", self.interval.to_string());
        if let Some(start_time) = self.start_time {
            params += &format!("&startTime={}", start_time);
        }
        if let Some(end_time) = self.end_time {
            params += &format!("&endTime={}", end_time);
        }
        if let Some(limit) = self.limit {
            params += &format!("&limit={}", limit);
        }
        params
    }
}