pub struct TickAggregator { /* private fields */ }Expand description
Incrementally builds candles out of arriving ticks.
Each call to TickAggregator::push returns the candles that closed as a
result of the new tick — normally at most one. Use
TickAggregator::flush at the end of a stream to capture the final open
bar.
§Gaps
By default a tick that jumps across one or more empty buckets simply opens
the next non-empty bar — the skipped buckets produce no candle, so the
output series can have time holes. Enable TickAggregator::with_gap_fill
to instead emit a flat placeholder candle for every skipped bucket, giving
downstream indicators an unbroken, evenly spaced series. To bound memory
against an adversarial timestamp jump, gap-filling refuses to emit more
than MAX_GAP_FILL_CANDLES placeholders in a single step; a larger gap
surfaces as an Error::Malformed so the caller can decide how to handle
the discontinuity.
Implementations§
Source§impl TickAggregator
impl TickAggregator
Sourcepub fn with_gap_fill(self, fill: bool) -> Self
pub fn with_gap_fill(self, fill: bool) -> Self
Enable or disable gap filling, returning the (re)configured aggregator.
When enabled, push emits a flat candle
(open == high == low == close, volume == 0) for every bucket that is
skipped between two consecutive ticks. The flat candle’s price is the
close of the bar that preceded the gap, so the series stays continuous.
Sourcepub const fn fills_gaps(&self) -> bool
pub const fn fills_gaps(&self) -> bool
Whether gap filling is enabled.
Sourcepub fn push(&mut self, tick: Tick) -> Result<Vec<Candle>>
pub fn push(&mut self, tick: Tick) -> Result<Vec<Candle>>
Push a tick. Returns every candle that closed as a result — an empty vector while the open bar keeps growing, one candle when a bar boundary is crossed, and (with gap filling enabled) additionally one flat candle per skipped bucket.
§Errors
Returns Error::Malformed if tick.timestamp goes backwards — both
across buckets (older than the open bar’s start) and within a bucket
(older than the last tick absorbed into it) — or if gap filling
overflows the timestamp range. Ticks sharing a timestamp are accepted.
Trait Implementations§
Source§impl Clone for TickAggregator
impl Clone for TickAggregator
Source§fn clone(&self) -> TickAggregator
fn clone(&self) -> TickAggregator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TickAggregator
impl RefUnwindSafe for TickAggregator
impl Send for TickAggregator
impl Sync for TickAggregator
impl Unpin for TickAggregator
impl UnsafeUnpin for TickAggregator
impl UnwindSafe for TickAggregator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more