Skip to main content

OhlcvAggregator

Struct OhlcvAggregator 

Source
pub struct OhlcvAggregator { /* private fields */ }
Expand description

Aggregates ticks into OHLCV bars.

Implementations§

Source§

impl OhlcvAggregator

Source

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.

Source

pub fn with_emit_empty_bars(self, enabled: bool) -> Self

Enable emission of synthetic zero-volume bars for skipped bar windows.

Source

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.

Source

pub fn current_bar(&self) -> Option<&OhlcvBar>

Current partial bar (if any).

Source

pub fn flush(&mut self) -> Option<OhlcvBar>

Flush the current partial bar as complete.

Source

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.

Source

pub fn bar_count(&self) -> u64

Total number of completed bars emitted by this aggregator (via feed or flush).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn symbol(&self) -> &str

The symbol this aggregator tracks.

Source

pub fn timeframe(&self) -> Timeframe

The timeframe used for bar alignment.

Source

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.

Source

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).

Source

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).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more