pub struct TradeHistory { /* private fields */ }Expand description
Trade history ring buffer for inter-bar feature computation
Implementations§
Source§impl TradeHistory
impl TradeHistory
Sourcepub fn new(config: InterBarConfig) -> Self
pub fn new(config: InterBarConfig) -> Self
Create new trade history with given configuration
Sourcepub fn push(&mut self, trade: &AggTrade)
pub fn push(&mut self, trade: &AggTrade)
Push a new trade to the history buffer
Automatically prunes old entries based on lookback mode, but preserves trades needed for lookback computation (timestamp < protected_until).
Sourcepub fn on_bar_open(&mut self, bar_open_time: i64)
pub fn on_bar_open(&mut self, bar_open_time: i64)
Notify that a new bar has opened at the given timestamp
This sets the protection threshold to ensure trades from before the bar opened are preserved for lookback computation. The protection extends until the next bar opens and calls this method again.
Sourcepub fn on_bar_close(&mut self)
pub fn on_bar_close(&mut self)
Notify that the current bar has closed
For BarRelative mode, records the current trade count as a bar boundary.
For other modes, this is a no-op. Protection is always kept until the
next bar opens.
Sourcepub fn get_lookback_trades(&self, bar_open_time: i64) -> Vec<&TradeSnapshot>
pub fn get_lookback_trades(&self, bar_open_time: i64) -> Vec<&TradeSnapshot>
Get trades for lookback computation (excludes trades at or after bar_open_time)
This is CRITICAL for temporal integrity - we only use trades that occurred BEFORE the current bar opened.
Sourcepub fn compute_features(&self, bar_open_time: i64) -> InterBarFeatures
pub fn compute_features(&self, bar_open_time: i64) -> InterBarFeatures
Sourcepub fn reset_bar_boundaries(&mut self)
pub fn reset_bar_boundaries(&mut self)
Reset bar boundary tracking (Issue #81)
Called at ouroboros boundaries. Clears bar close indices but preserves trade history — trades are still valid lookback data for the first bar of the new segment.
Trait Implementations§
Source§impl Clone for TradeHistory
impl Clone for TradeHistory
Source§fn clone(&self) -> TradeHistory
fn clone(&self) -> TradeHistory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more