rangebar

Crates.iorangebar
lib.rsrangebar
version0.9.1
created_at2025-09-15 06:49:51.261793+00
updated_at2025-09-25 01:42:49.464597+00
descriptionNon-lookahead range bar construction for cryptocurrency trading with temporal integrity guarantees
homepagehttps://github.com/Eon-Labs/rangebar
repositoryhttps://github.com/Eon-Labs/rangebar
max_upload_size
id1839503
size1,030,105
Terry Li (terrylica)

documentation

https://docs.rs/rangebar

README

rangebar

Crates.io Documentation License: MIT

Non-lookahead range bar construction for cryptocurrency trading with temporal integrity guarantees.

Quick Start

Add this to your Cargo.toml:

[dependencies]
rangebar = "0.5"

Usage

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

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

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

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

for bar in bars {
    println!("Bar: O={} H={} L={} C={} V={}",
             bar.open, bar.high, bar.low, bar.close, bar.volume);
}

Algorithm

Range bars close when price moves ±threshold basis points from the bar's opening price:

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

Features

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

License

MIT license. See LICENSE for details.

Commit count: 98

cargo fmt