Skip to content

Commit

Permalink
wip: add close method to aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantrontal committed Apr 4, 2024
1 parent 7b84f21 commit a1d552f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub trait Aggregator<Candle, T: TakerTrade> {
/// Some output only when a new candle has been created,
/// otherwise it returns None
fn update(&mut self, trade: &T) -> Option<Candle>;

/// Close current active candle and return it
///
/// # Returns:
/// Last active candle, or None if candle was already finalized
fn close(&mut self) -> Option<Candle>;
}

/// An `Aggregator` that is generic over
Expand Down Expand Up @@ -66,6 +72,15 @@ where
}
None
}

fn close(&mut self) -> Option<C> {
if !self.candle.finalized() {
self.candle.finalize();
return Some(self.candle.clone());
}

None
}
}

#[cfg(test)]
Expand Down

0 comments on commit a1d552f

Please # to comment.