pub struct OhlcvAggregator { /* private fields */ }Expand description
Aggregates ticks into OHLCV bars.
Implementations§
Source§impl OhlcvAggregator
impl OhlcvAggregator
Sourcepub fn new(
symbol: impl Into<String>,
timeframe: Timeframe,
) -> Result<Self, StreamError>
pub fn new( symbol: impl Into<String>, timeframe: Timeframe, ) -> Result<Self, StreamError>
Create a new aggregator for symbol at timeframe.
Returns an error if timeframe.duration_ms() is zero, which would make
bar boundary alignment undefined.
Sourcepub fn with_emit_empty_bars(self, enabled: bool) -> Self
pub fn with_emit_empty_bars(self, enabled: bool) -> Self
Enable emission of synthetic zero-volume bars for skipped bar windows.
Sourcepub fn feed(
&mut self,
tick: &NormalizedTick,
) -> Result<Vec<OhlcvBar>, StreamError>
pub fn feed( &mut self, tick: &NormalizedTick, ) -> Result<Vec<OhlcvBar>, StreamError>
Feed a tick. Returns completed bars (including any empty gap bars when
emit_empty_bars is true). At most one real completed bar plus zero or
more empty bars can be returned per call.
Bar boundaries are aligned using the exchange-side timestamp
(exchange_ts_ms) when available, falling back to the local system
clock (received_at_ms). Using the exchange timestamp avoids
misalignment caused by variable network latency.
Sourcepub fn current_bar(&self) -> Option<&OhlcvBar>
pub fn current_bar(&self) -> Option<&OhlcvBar>
Current partial bar (if any).
Sourcepub fn last_bar(&self) -> Option<&OhlcvBar>
pub fn last_bar(&self) -> Option<&OhlcvBar>
The most recently completed bar emitted by feed or
flush. Returns None if no bar has been completed yet.
Unlike current_bar, this bar is always complete.
Sourcepub fn bar_count(&self) -> u64
pub fn bar_count(&self) -> u64
Total number of completed bars emitted by this aggregator (via feed or flush).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Discard the in-progress bar and reset the bar counter to zero.
Useful for backtesting rewind or when restarting aggregation from a new anchor point. Does not affect the aggregator’s symbol or timeframe.
Sourcepub fn total_volume(&self) -> Decimal
pub fn total_volume(&self) -> Decimal
Cumulative traded volume across all completed bars emitted by this aggregator.
Does not include the current partial bar’s volume. Reset to zero by
reset.
Sourcepub fn peak_volume(&self) -> Option<Decimal>
pub fn peak_volume(&self) -> Option<Decimal>
Maximum single-bar volume seen across all completed bars.
Returns None if no bars have been completed yet. Reset to None by
reset.
Sourcepub fn min_volume(&self) -> Option<Decimal>
pub fn min_volume(&self) -> Option<Decimal>
Minimum single-bar volume seen across all completed bars.
Returns None if no bars have been completed yet. Reset to None by
reset.
Sourcepub fn volume_range(&self) -> Option<(Decimal, Decimal)>
pub fn volume_range(&self) -> Option<(Decimal, Decimal)>
Volume range across completed bars: (min_volume, peak_volume).
Returns None if no bars have been completed yet. Useful for
normalizing volume signals to the observed range.
Sourcepub fn average_volume(&self) -> Option<Decimal>
pub fn average_volume(&self) -> Option<Decimal>
Average volume per completed bar: total_volume / bars_emitted.
Returns None if no bars have been completed yet (avoids division by zero).
Sourcepub fn window_progress(&self, now_ms: u64) -> Option<f64>
pub fn window_progress(&self, now_ms: u64) -> Option<f64>
Fraction of the current bar’s time window that has elapsed, in [0.0, 1.0].
Returns None if no bar is in progress (no ticks seen since last
flush/reset). now_ms should be ≥ the current bar’s bar_start_ms;
values before the start clamp to 0.0.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true if a bar is currently in progress (at least one tick has
been fed since the last flush or reset).
Sourcepub fn vwap_current(&self) -> Option<Decimal>
pub fn vwap_current(&self) -> Option<Decimal>
Volume-weighted average price of the current in-progress bar.
Returns None if no bar is currently being built or the bar has zero
volume (should not happen with real ticks).