From a1d552f9ab7dec273918fe7a0ee2873bb1166b40 Mon Sep 17 00:00:00 2001 From: ivaaaan Date: Thu, 4 Apr 2024 21:50:47 +0700 Subject: [PATCH] wip: add close method to aggregator --- src/aggregator.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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)]