fix(collector): separate Binance event and trade clocks - #850
Conversation
📝 WalkthroughWalkthroughThe change centralizes Binance clock validation across market-tape parsers. It allows fresh events with older transaction times and reports event, trade, and receive ages. Raw-trade archiving now uses a shared parser and preserves detailed failure context. ChangesBinance clock validation and raw-trade flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rust_hft/data-pipelines/core/src/binance_market_tape.rs (1)
1099-1103: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid the per-frame allocation in
validate_trade_clocks.
format!("{kind} E")allocates for every aggregate-trade, raw-trade, and force-order frame. Raw trades use this hot path. Pass the static event-clock label from each caller.Proposed refactor
fn validate_trade_clocks( event_time_ms: u64, trade_time_ms: u64, received_at_ns: u64, kind: &str, + event_clock_kind: &str, ) -> Result<()> { @@ - if let Err(error) = validate_receive_clock(event_time_ms, received_at_ns, &format!("{kind} E")) + if let Err(error) = validate_receive_clock(event_time_ms, received_at_ns, event_clock_kind)- validate_trade_clocks(event_time_ms, trade_time_ms, received_at_ns, "raw trade")?; + validate_trade_clocks( + event_time_ms, + trade_time_ms, + received_at_ns, + "raw trade", + "raw trade E", + )?;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust_hft/data-pipelines/core/src/binance_market_tape.rs` around lines 1099 - 1103, Update validate_trade_clocks and its callers to accept a static event-clock label, passing the appropriate literal from each aggregate-trade, raw-trade, and force-order path. Replace the per-frame format!("{kind} E") construction in validate_receive_clock with that label while preserving the existing validation and error context.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rust_hft/data-pipelines/core/src/binance_market_tape.rs`:
- Around line 1099-1103: Update validate_trade_clocks and its callers to accept
a static event-clock label, passing the appropriate literal from each
aggregate-trade, raw-trade, and force-order path. Replace the per-frame
format!("{kind} E") construction in validate_receive_clock with that label while
preserving the existing validation and error context.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f9b90f23-0a11-4a7b-9f1a-0e3d6fa7d860
📒 Files selected for processing (2)
rust_hft/data-pipelines/core/src/binance_market_tape.rsrust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Issue relationship
Refs #846. The runtime outcome remains open until its own Shadow and OSS evidence passes.
What changed
The 30-second threshold, fail-closed trade/depth behavior, session policy, deployment, Gate, cutover, and Live behavior are unchanged.
Evidence
Sources
Binance documents E as event time and T as trade/transaction time; Spot bookTicker carries neither field.
Summary by CodeRabbit