Skip to content

fix(data): enforce Binance raw trade range continuity - #122

Closed
proerror77 wants to merge 2 commits into
mainfrom
codex/binance-aggregate-trade-range-continuity
Closed

proerror77 wants to merge 2 commits into
mainfrom
codex/binance-aggregate-trade-range-continuity

Conversation

@proerror77

Copy link
Copy Markdown
Owner

Change contract: reject Binance aggregate-trade sequences when the raw trade id range is not contiguous between consecutive events.

Out of scope: source-clock tolerance, replay-unsafe recovery, downstream assembler changes, and any new schema fields.

Dependency or merge order: independent of #121; may merge after or before it, but does not depend on additional Binance changes.

Focused validation: cargo check -p hft-collector --locked; cargo clippy -p hft-collector --all-targets --features collector-binance --no-deps --locked -- -D warnings; cargo test -p hft-collector --features collector-binance --locked.

Rollout/rollback impact: narrow validator tightening only; rollback is the reverse commit with no data migration.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@proerror77, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c47d5cc8-bce9-4980-ace2-2ef6eb0234f0

📥 Commits

Reviewing files that changed from the base of the PR and between 27afc2e and 2e03658.

📒 Files selected for processing (2)
  • rust_hft/data-pipelines/core/src/binance_market_tape.rs
  • rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/binance-aggregate-trade-range-continuity

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proerror77

Copy link
Copy Markdown
Owner Author

Closing after focused protocol review. Binance documents f/l as the first and last raw trade IDs inside one aggTrade event, but does not guarantee cross-event previous.l + 1 == next.f; USD-M also excludes insurance-fund and ADL trades from aggTrade aggregation. Treating this undocumented relation as a shared Spot+USD-M trust invariant can reject legitimate data. Aggregate-trade ID continuity remains the supported frame-loss guard. This PR also picked up an unrelated collector clippy fix already owned by merged #118, so it is not a valid focused rollback unit.

@proerror77 proerror77 closed this Jul 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e036584d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let expected_first_trade_id = previous_last_trade_id
.checked_add(1)
.context("aggregate trade raw trade id overflow")?;
if trade.first_trade_id != expected_first_trade_id {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid rejecting valid futures aggTrade raw-ID skips

When MARKET=usdm, Config::stream_urls subscribes to Binance's futures @aggTrade stream, whose docs say only market trades are aggregated and insurance-fund/ADL trades are not returned (https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Mini-Tickers-Stream#aggregate-trade-streams). If one of those omitted executions consumes a raw trade ID, the next valid aggregate trade can have f > previous_l + 1; this equality then writes aggregate_trade_gap, returns an error, and the archiver keeps reconnecting from the stale validator state rather than accepting the live futures stream.

Useful? React with 👍 / 👎.

@proerror77
proerror77 deleted the codex/binance-aggregate-trade-range-continuity branch July 17, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant