use crate::dtf;
pub mod time_bars;
pub mod volume_bars;
pub mod tick_bars;
pub mod dollar_bars;
pub mod candlestick_graph;
use self::dtf::update::Update;
type Time = u64;
type Price = f32;
type Volume = f32;
type Scale = u16;
#[derive(PartialOrd, PartialEq, Clone, Copy, Debug)]
pub struct Candle {
pub start: Time,
pub end: Time,
pub open: Price,
pub high: Price,
pub low: Price,
pub close: Price,
pub volume: Volume,
}
impl Eq for Candle {}
impl Candle {
pub fn to_csv(&self) -> String {
format!(
"{},{},{},{},{},{},{}",
self.start,
self.end,
self.open,
self.high,
self.low,
self.close,
self.volume
)
}
}
pub fn draw_updates(ups: &[Update]) -> String {
let mut candles = time_bars::TimeBars::from(ups);
candles.insert_continuation_candles();
candlestick_graph::CandleStickGraph::new(20, candles.clone()).draw()
}
pub trait Sampler {
fn is_sample(&mut self, update: &Update) -> bool;
fn reset(&mut self);
}
use std::ops::DerefMut;
impl<T: DerefMut<Target=dyn Sampler>> Sampler for T {
fn is_sample(&mut self, update:&Update) -> bool {
self.deref_mut().is_sample(update)
}
fn reset(&mut self) {
self.deref_mut().reset()
}
}