rangebar-streaming
Real-time streaming processor for range bars with bounded memory and circuit breaker pattern.
Overview
rangebar-streaming provides a streaming implementation of the range bar algorithm optimized for real-time tick processing with bounded memory usage. Suitable for live trading systems, WebSocket data ingestion, and continuous market analysis.
Features
- Bounded Memory: Configurable buffer size prevents memory exhaustion
- Circuit Breaker Pattern: Fault tolerance with automatic error threshold detection
- Real-Time Metrics: Processing statistics for monitoring
- Async Processing: Tokio-based async stream processing
- Graceful Degradation: Handles errors without cascade failures
Usage
Basic Streaming
use StreamingProcessor;
use StreamExt;
// Create processor with 25 BPS (0.25%) threshold
let mut processor = new?; // v3.0.0: 250 = 25 BPS
// Process async stream
let metrics = processor.process_stream.await?;
println!;
println!;
Custom Configuration
use ;
let config = StreamingProcessorConfig ;
let mut processor = with_config?;
Replay Buffer
For testing and development, use the replay buffer for time-aware playback:
use ReplayBuffer;
let mut buffer = new; // 10k trade buffer
// Push trades
for trade in trades
// Get trades from specific timestamp
let recent_trades = buffer.get_trades_from;
Metrics
Circuit Breaker
The circuit breaker pattern prevents cascade failures:
- Closed State: Normal operation, all trades processed
- Open State: Error threshold exceeded, processing halted
- Half-Open State: Testing if errors cleared
// Circuit breaker activates when error count exceeds threshold
if metrics.circuit_breaker_active
Performance Characteristics
- Memory Usage: O(buffer_size) - bounded and configurable
- Throughput: Moderate (single-threaded async processing)
- Latency: Low (< 1ms per trade in normal conditions)
- Parallelism: Single-threaded (use rangebar-batch for multi-threaded)
Comparison: Streaming vs Batch
| Feature | Streaming | Batch |
|---|---|---|
| Memory Usage | Bounded | Unbounded |
| Throughput | Moderate | High |
| Parallelism | Single-threaded | Multi-threaded (Rayon) |
| Real-time | Yes | No |
| Use Case | Live trading | Historical analysis |
| Circuit Breaker | Yes | No |
Dependencies
- rangebar-core - Core algorithm and types
- rangebar-providers - Data fetching
- tokio - Async runtime
- futures - Stream processing
Version
Current version: 5.0.0 (modular crate architecture)
Documentation
- Architecture:
../../docs/ARCHITECTURE.md - Examples:
../../examples/interactive/
License
See LICENSE file in the repository root.