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
76
77
78
79
80
81
82
83
84
85
use serde::{Serialize, Deserialize};
use chrono::{DateTime, Utc};
use ta::{Close, High, Low, Open, Volume};

/// Normalised Trade model to be returned from an [ExchangeClient].
#[derive(Debug, Deserialize, Serialize)]
pub struct Trade {
    pub trade_id: String,
    pub timestamp: String,
    pub ticker: String,
    pub price: f64,
    pub quantity: f64,
    pub buyer: BuyerType,
}

/// Defines if the buyer in a [Trade] is a market maker.
#[derive(Debug, Deserialize, Serialize)]
pub enum BuyerType {
    MarketMaker,
    Taker,
}

/// Defines the possible intervals that a [Candle] represents.
#[derive(Debug, Deserialize, Serialize)]
pub enum Interval {
    Minute1, Minute3, Minute5, Minute15, Minute30,
    Hour1, Hour2, Hour4, Hour6, Hour8, Hour12,
    Day1, Day3,
    Week1,
    Month1,
}

/// Normalised OHLCV data from an [Interval] with the associated [DateTime] UTC timestamp;
#[derive(Debug, Deserialize, Serialize, PartialOrd, PartialEq)]
pub struct Candle {
    pub timestamp: DateTime<Utc>,
    pub open: f64,
    pub high: f64,
    pub low: f64,
    pub close: f64,
    pub volume: f64,
}

impl Default for Candle {
    fn default() -> Self {
        Self {
            timestamp: Utc::now(),
            open: 1000.0,
            high: 1100.0,
            low: 900.0,
            close: 1050.0,
            volume: 1000000000.0,
        }
    }
}

impl Open for Candle {
    fn open(&self) -> f64 {
        self.open
    }
}

impl High for Candle {
    fn high(&self) -> f64 {
        self.high
    }
}

impl Low for Candle {
    fn low(&self) -> f64 {
        self.low
    }
}

impl Close for Candle {
    fn close(&self) -> f64 {
        self.close
    }
}

impl Volume for Candle {
    fn volume(&self) -> f64 {
        self.volume
    }
}