Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add unfinished_candle method #14

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ 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>;

/// Get a reference to an unfinished `Candle`.
/// Accessing a `Candle` using this method does not guarantee that the `AggregationRule` is respected.
/// It is generally advised to call `update` instead and use the resulting `Candle` if its `Some`.
fn unfinished_candle(&self) -> &Candle;
}

/// An `Aggregator` that is generic over
Expand Down Expand Up @@ -64,6 +69,10 @@ where
self.candle.update(trade);
None
}

fn unfinished_candle(&self) -> &C {
&self.candle
}
}

#[cfg(test)]
Expand Down