fix(polymarket): publish final batched book state - #35
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPolymarket CLOB price-change batches now coalesce fresh deltas before publishing quotes, validate final books for crossed prices, and propagate errors. Tests cover final-state publication, crossed books, stale updates, and the updated ChangesPolymarket batch coalescing
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WebSocketHandler
participant BatchProcessor
participant CachedBook
participant QuotePublisher
WebSocketHandler->>BatchProcessor: Forward PriceChange batch
BatchProcessor->>CachedBook: Apply fresh deltas
CachedBook-->>BatchProcessor: Final changed book states
BatchProcessor->>QuotePublisher: Publish validated quote updates
BatchProcessor-->>WebSocketHandler: Return updates or crossed-book error
🚥 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 846fee2060
ℹ️ 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".
| } | ||
| books.entry(token_id.clone()).or_default().apply(entry); | ||
| last_timestamp.insert(token_id.clone(), change.timestamp); | ||
| if last_entries.insert(token_id.clone(), entry).is_none() { |
There was a problem hiding this comment.
Preserve both top-of-book sizes while coalescing batches
When a price_change batch arrives before a Book snapshot has initialized ClobBookState (or immediately after reconnect), apply leaves the book empty and quote can only recover sizes from the single entry passed here. Because last_entries.insert overwrites earlier entries for the same token, a batch that updates the bid and then the ask publishes only the last side's size; the previous per-entry flow let the executor observe and carry both sides. This leaves strategies/backtests with missing or stale liquidity until a full book snapshot arrives, so the coalescing needs to retain per-token top bid and ask size metadata, not just the last entry.
Useful? React with 👍 / 👎.
Summary
price_changeentry before publishing a quoteValidation
cargo test -p ploy-market-data --features live --locked feeds::tests::clob_ -- --nocapturecargo test -p ploy-market-data --features live --lockedcargo fmt --all -- --checkgit diff --checkSummary by CodeRabbit
Bug Fixes
Documentation