RangeBarProcessor

Struct RangeBarProcessor 

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

Range bar processor with non-lookahead bias guarantee

Implementations§

Source§

impl RangeBarProcessor

Source

pub fn new(threshold_bps: u32) -> Result<Self, ProcessingError>

Create new processor with given threshold

§Arguments
  • threshold_bps - Threshold in tenths of basis points (0.1bps units)
    • Example: 250 → 25bps = 0.25%
    • Example: 10 → 1bps = 0.01%
    • Minimum: 1 → 0.1bps = 0.001%
§Breaking Change (v3.0.0)

Prior to v3.0.0, threshold_bps was in 1bps units. Migration: Multiply all threshold values by 10.

Source

pub fn process_single_trade( &mut self, trade: AggTrade, ) -> Result<Option<RangeBar>, ProcessingError>

Process a single trade and return completed bar if any

Maintains internal state for streaming use case. State persists across calls until a bar completes (threshold breach), enabling get_incomplete_bar().

§Arguments
  • trade - Single aggregated trade to process
§Returns

Some(RangeBar) if a bar was completed, None otherwise

§State Management
  • First trade: Initializes new bar state
  • Subsequent trades: Updates existing bar or closes on breach
  • Breach: Returns completed bar, starts new bar with breaching trade
Source

pub fn get_incomplete_bar(&self) -> Option<RangeBar>

Get any incomplete bar currently being processed

Returns clone of current bar state for inspection without consuming it. Useful for final bar at stream end or progress monitoring.

§Returns

Some(RangeBar) if bar is in progress, None if no active bar

Source

pub fn process_agg_trade_records_with_incomplete( &mut self, agg_trade_records: &[AggTrade], ) -> Result<Vec<RangeBar>, ProcessingError>

Process AggTrade records into range bars including incomplete bars for analysis

§Arguments
  • agg_trade_records - Slice of AggTrade records sorted by (timestamp, agg_trade_id)
§Returns

Vector of range bars including incomplete bars at end of data

§Warning

This method is for analysis purposes only. Incomplete bars violate the fundamental range bar algorithm and should not be used for production trading.

Source

pub fn process_agg_trade_records( &mut self, agg_trade_records: &[AggTrade], ) -> Result<Vec<RangeBar>, ProcessingError>

Process Binance aggregated trade records into range bars

This is the primary method for converting AggTrade records (which aggregate multiple individual trades) into range bars based on price movement thresholds.

§Parameters
  • agg_trade_records - Slice of AggTrade records sorted by (timestamp, agg_trade_id) Each record represents multiple individual trades aggregated at same price
§Returns

Vector of completed range bars (ONLY bars that breached thresholds). Each bar tracks both individual trade count and AggTrade record count.

Source

pub fn process_agg_trade_records_with_options( &mut self, agg_trade_records: &[AggTrade], include_incomplete: bool, ) -> Result<Vec<RangeBar>, ProcessingError>

Process AggTrade records with options for including incomplete bars

Batch processing mode: Clears any existing state before processing. Use process_single_trade() for stateful streaming instead.

§Parameters
  • agg_trade_records - Slice of AggTrade records sorted by (timestamp, agg_trade_id)
  • include_incomplete - Whether to include incomplete bars at end of processing
§Returns

Vector of range bars (completed + incomplete if requested)

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