Crate rangebar

Crate rangebar 

Source
Expand description

Non-lookahead range bar construction for cryptocurrency trading.

This crate provides algorithms for constructing range bars from aggTrade data with temporal integrity guarantees, ensuring no lookahead bias in financial backtesting.

§Meta-Crate

This is a meta-crate that re-exports all rangebar sub-crates for backward compatibility with v4.0.0. New code should depend on specific sub-crates directly:

  • rangebar-core - Core algorithm and types
  • rangebar-providers - Data providers (Binance, Exness)
  • rangebar-config - Configuration management
  • rangebar-io - I/O operations and Polars integration
  • rangebar-streaming - Real-time streaming processor
  • rangebar-batch - Batch analytics engine
  • rangebar-cli - Command-line tools

§Features

  • core - Core algorithm (always enabled)
  • providers - Data providers (Binance, Exness)
  • config - Configuration management
  • io - I/O operations and Polars integration
  • streaming - Real-time streaming processor
  • batch - Batch analytics engine
  • full - Enable all features

§Basic Usage

use rangebar::{RangeBarProcessor, AggTrade, FixedPoint};

// Create processor with 250 basis points threshold
let mut processor = RangeBarProcessor::new(250);

// Create sample aggTrade
let trade = AggTrade {
    agg_trade_id: 1,
    price: FixedPoint::from_str("50000.0").unwrap(),
    volume: FixedPoint::from_str("1.0").unwrap(),
    first_trade_id: 1,
    last_trade_id: 1,
    timestamp: 1609459200000,
    is_buyer_maker: false,
    is_best_match: None,
};

// Process aggTrade records into range bars
let agg_trade_records = vec![trade];
let bars = processor.process_agg_trade_records(&agg_trade_records).unwrap();

§Dual-Path Architecture

§Streaming Mode (Real-time)

use rangebar::streaming::StreamingProcessor;

let threshold_bps = 25; // 0.25% range bars
let processor = StreamingProcessor::new(threshold_bps);
// Real-time processing with bounded memory

§Batch Mode (Analytics)

use rangebar::batch::BatchAnalysisEngine;
use rangebar::core::types::RangeBar;

let range_bars: Vec<RangeBar> = vec![]; // Your range bar data
let engine = BatchAnalysisEngine::new();
// let result = engine.analyze_single_symbol(&range_bars, "BTCUSDT").unwrap();

Re-exports§

pub use rangebar_core as core;

Modules§

fixed_point
Fixed-point arithmetic module (legacy compatibility)
range_bars
Range bar processor module (legacy compatibility)
types
Core types module (legacy compatibility)

Structs§

AggTrade
Aggregate trade data from Binance markets
ExportRangeBarProcessor
Export-oriented range bar processor for streaming use cases
FixedPoint
Fixed-point decimal representation using i64 with 8 decimal precision
RangeBar
Range bar with OHLCV data and market microstructure enhancements
RangeBarProcessor
Range bar processor with non-lookahead bias guarantee

Enums§

ProcessingError
Processing errors

Constants§

DESCRIPTION
NAME
VERSION
Version information

Functions§

init
Library initialization and configuration