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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#[derive(Debug, Clone)] pub struct Candlestick<Instrument, Interval, Time, Price, Volume> where Instrument: Clone, Interval: Clone, Time: Clone, Price: Clone, Volume: Clone, { pub instrument: Instrument, pub interval: Interval, pub time: Time, pub open: Price, pub high: Price, pub low: Price, pub close: Price, pub volume: Volume, } impl<Instrument, Interval, Time, Price, Volume> Candlestick<Instrument, Interval, Time, Price, Volume> where Instrument: Clone, Interval: Clone, Time: Clone, Price: Clone, Volume: Clone, { pub fn new( instrument: Instrument, interval: Interval, time: Time, open: Price, high: Price, low: Price, close: Price, volume: Volume, ) -> Candlestick<Instrument, Interval, Time, Price, Volume> { Candlestick { instrument, interval, time, open, high, low, close, volume, } } } #[cfg(feature = "time_series")] extern crate time_series; #[cfg(feature = "time_series")] use time_series::DataPoint; #[cfg(feature = "time_series")] impl<Instrument, Interval, Time, Price, Volume> Candlestick<Instrument, Interval, Time, Price, Volume> where Instrument: Clone, Interval: Clone, Time: Clone, Price: Clone, Volume: Clone, { pub fn open_to_datapoint(&self) -> DataPoint<Time, Price> { DataPoint { time: self.time.clone(), data: self.open.clone(), } } pub fn high_to_datapoint(&self) -> DataPoint<Time, Price> { DataPoint { time: self.time.clone(), data: self.high.clone(), } } pub fn low_to_datapoint(&self) -> DataPoint<Time, Price> { DataPoint { time: self.time.clone(), data: self.low.clone(), } } pub fn close_to_datapoint(&self) -> DataPoint<Time, Price> { DataPoint { time: self.time.clone(), data: self.close.clone(), } } pub fn volume_to_datapoint(&self) -> DataPoint<Time, Volume> { DataPoint { time: self.time.clone(), data: self.volume.clone(), } } }