Expand description
Non-lookahead range bar construction for cryptocurrency and forex trading.
This crate provides algorithms for constructing range bars from tick data with temporal integrity guarantees, ensuring no lookahead bias in financial backtesting.
§Installation
Add to your Cargo.toml:
[dependencies]
rangebar = "6.1"§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 typesrangebar-providers- Data providers (Binance, Exness)rangebar-config- Configuration managementrangebar-io- I/O operations and Polars integrationrangebar-streaming- Real-time streaming processorrangebar-batch- Batch analytics enginerangebar-cli- Command-line tools
§Features
core- Core algorithm (always enabled)providers- Data providers (Binance, Exness)config- Configuration managementio- I/O operations and Polars integrationstreaming- Real-time streaming processorbatch- Batch analytics enginefull- Enable all features
§Basic Usage
use rangebar::{RangeBarProcessor, AggTrade, FixedPoint};
// Create processor with 25 basis points threshold (0.25%)
let mut processor = RangeBarProcessor::new(250).unwrap();
// 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_decimal_bps = 250; // 25 bps = 0.25% range bars
let processor = StreamingProcessor::new(threshold_decimal_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();§Links
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
- Export
Range BarProcessor - Export-oriented range bar processor for streaming use cases
- Fixed
Point - Fixed-point decimal representation using i64 with 8 decimal precision
- Range
Bar - Range bar with OHLCV data and market microstructure enhancements
- Range
BarProcessor - Range bar processor with non-lookahead bias guarantee
Enums§
- Processing
Error - Processing errors
Constants§
- DESCRIPTION
- NAME
- VERSION
- Version information
Functions§
- init
- Library initialization and configuration