# rangebar
[](https://crates.io/crates/rangebar)
[](https://docs.rs/rangebar)
[](https://opensource.org/licenses/MIT)
Non-lookahead range bar construction for cryptocurrency trading with temporal integrity guarantees.
## Quick Start
Add this to your `Cargo.toml`:
```toml
[dependencies]
rangebar = "0.5"
```
## Usage
```rust
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 aggTrade records into range bars
let agg_trade_records = vec![trade];
let bars = processor.process_agg_trade_records(&agg_trade_records).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](LICENSE) for details.