use crate::{CandleComponent, CandleComponentUpdate, TakerTrade};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Low {
low: f64,
}
impl Default for Low {
fn default() -> Self {
Self { low: f64::MAX }
}
}
impl CandleComponent<f64> for Low {
#[inline(always)]
fn value(&self) -> f64 {
self.low
}
#[inline(always)]
fn reset(&mut self) {
self.low = f64::MAX;
}
}
impl<T: TakerTrade> CandleComponentUpdate<T> for Low {
#[inline(always)]
fn update(&mut self, trade: &T) {
if trade.price() < self.low {
self.low = trade.price();
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn low() {
let mut m = Low::default();
for t in &crate::candle_components::tests::TRADES {
m.update(t);
}
assert_eq!(m.value(), 100.0);
}
}