diff --git a/src/aggregator.rs b/src/aggregator.rs index 3afd4f8..cc23156 100644 --- a/src/aggregator.rs +++ b/src/aggregator.rs @@ -13,6 +13,12 @@ pub trait Aggregator { /// Some output only when a new candle has been created, /// otherwise it returns None fn update(&mut self, trade: &T) -> Option; + + /// Close current active candle and return it + /// + /// # Returns: + /// Last active candle, or None if candle was already finalized + fn close(&mut self) -> Option; } /// An `Aggregator` that is generic over @@ -66,6 +72,15 @@ where } None } + + fn close(&mut self) -> Option { + if !self.candle.finalized() { + self.candle.finalize(); + return Some(self.candle.clone()); + } + + None + } } #[cfg(test)]