Crate rangebar

Crate rangebar 

Source
Expand description

Non-lookahead range bar construction for cryptocurrency trading.

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

§Features

  • Non-lookahead bias range bar construction
  • Fixed-point arithmetic for precision
  • Streaming and batch processing modes
  • Tier-1 cryptocurrency symbol discovery
  • Pure Rust implementation

§Basic Usage

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

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

// Create sample trade
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,
};

// Process trades into range bars
let trades = vec![trade];
let bars = processor.process_trades(&trades).unwrap();

§Tier-1 Symbols

use rangebar::{is_tier1_symbol, get_tier1_symbols};

// Check if a symbol is Tier-1 (available across all Binance futures markets)
assert!(is_tier1_symbol("BTC"));
assert!(is_tier1_symbol("ETH"));
assert!(!is_tier1_symbol("SHIB"));

// Get all Tier-1 symbols
let symbols = get_tier1_symbols();
assert_eq!(symbols.len(), 18);

§Algorithm

Range bars close when price moves ±threshold% from the bar’s opening price:

  1. Non-lookahead bias: Thresholds computed only from bar open price
  2. Breach inclusion: Breaching trade included in closing bar
  3. Fixed thresholds: Never recalculated during bar lifetime

Re-exports§

pub use config::Settings;
pub use fixed_point::FixedPoint;
pub use range_bars::ExportRangeBarProcessor;
pub use range_bars::ProcessingError;
pub use range_bars::RangeBarProcessor;
pub use tier1::TIER1_SYMBOLS;
pub use tier1::get_tier1_symbols;
pub use tier1::get_tier1_usdt_pairs;
pub use tier1::is_tier1_symbol;
pub use types::AggTrade;
pub use types::RangeBar;
pub use streaming_processor::MetricsSummary;
pub use streaming_processor::RangeBarStream;
pub use streaming_processor::StreamingError;
pub use streaming_processor::StreamingMetrics;
pub use streaming_processor::StreamingProcessor;
pub use streaming_processor::StreamingProcessorConfig;

Modules§

config
Configuration management for the rangebar crate.
fixed_point
Fixed-point arithmetic for precise decimal calculations without floating point errors
range_bars
Core range bar processing algorithm
range_bars_debug
Debug module to reproduce and fix the 0.5% threshold algorithm bug
statistics
Streaming-optimized statistics for range bar analysis
streaming_processor
tier1
Tier-1 Symbol Discovery and Multi-Market Analysis
types
Type definitions for range bar processing

Constants§

DESCRIPTION
NAME
VERSION
Version information

Functions§

init
Library initialization and configuration