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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use rust_decimal::Decimal;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Kline {
pub open_time: i64,
pub open: Decimal,
pub high: Decimal,
pub low: Decimal,
pub close: Decimal,
pub volume: Decimal,
pub close_time: i64,
pub quote_asset_volume: Decimal,
pub number_of_trades: i64,
pub taker_buy_base_asset_volume: Decimal,
pub taker_buy_quote_asset_volume: Decimal,
pub ignore: Decimal,
}
impl Kline {
pub fn is_green(&self) -> bool {
self.close >= self.open
}
pub fn is_red(&self) -> bool {
self.close < self.open
}
pub fn middle(&self) -> Decimal {
(self.low + self.high) / Decimal::new(2, 0)
}
pub fn middle_body(&self) -> Decimal {
(self.open + self.close) / Decimal::new(2, 0)
}
pub fn average(&self) -> Decimal {
(self.low + self.open + self.close + self.high) / Decimal::new(4, 0)
}
}