Skip to content

feat(polymarket): record quote collection outcomes - #238

Merged
proerror77 merged 3 commits into
mainfrom
codex/polymarket-quote-completeness-220
Jul 23, 2026
Merged

feat(polymarket): record quote collection outcomes#238
proerror77 merged 3 commits into
mainfrom
codex/polymarket-quote-completeness-220

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Change contract: The production Polymarket CLOB WebSocket path records explicit per-token collection failures and truthful executable, one-sided, empty, and non-executable quote outcomes with source and received timestamps.

Out of scope: Uploader/manifest eligibility and shadow-gate changes are owned by the stacked validation PR; production deployment/cutover, snapshot construction, evaluator/MCTS, and research logic are unchanged.

Dependency or merge order: Base layer. Merge this PR before codex/polymarket-quote-validation-220.

Focused validation: ploy-market-data live library tests (125 passed); recorded feed tests (10 passed); existing MarketUpdate tag stability test; new-ploy-runner full-feature cargo check; final read-only spec and standards reviews found no blocker.

Rollout/rollback impact: No deployment is performed. Runtime strategies still receive the existing fail-closed empty quote on WS failure, while the raw recorder stores the failure and excludes only its exact synthetic empty pair. Revert this PR to restore the prior recording contract.

Issue: Producer/recording layer for #220.

Summary by CodeRabbit

  • New Features
    • Added structured notifications when quote collection fails, including failure details and affected tokens.
    • Recorded market data now includes quote request status and collection-result classifications.
  • Bug Fixes
    • Invalid prices, sizes, timestamps, and market updates are rejected instead of being silently ignored.
    • Improved handling of tradeable prices, incomplete books, and websocket failures.
    • Empty fallback quotes are emitted consistently after collection failures.
  • Configuration
    • Updated search policy snapshots for BTC and SOL five-minute market research missions.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: efc1ee8c-2629-4524-b329-ea4564d8448b

📥 Commits

Reviewing files that changed from the base of the PR and between 737e291 and e76ebe8.

📒 Files selected for processing (8)
  • rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json
  • rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json
  • rust_hft/prediction-markets/crates/ploy-market-contracts/src/events.rs
  • rust_hft/prediction-markets/crates/ploy-market-data/src/feeds.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/factors.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/examples/run_backtest.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/engine.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/recorded.rs

📝 Walkthrough

Walkthrough

Changes

Polymarket CLOB ingestion now validates malformed market data, propagates timestamp and book errors, and emits structured QuoteCollectionFailure updates before fail-closed empty quotes. Recording adds quote outcome classification and synthetic-empty suppression. Consumers handle the new update variant, and BTC/SOL mission snapshot identifiers are refreshed.

Polymarket quote handling

Layer / File(s) Summary
Quote failure market-update contract
rust_hft/prediction-markets/crates/ploy-market-contracts/src/events.rs, rust_hft/prediction-markets/crates/ploy-research/src/factors.rs, rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/...
Adds MarketUpdate::QuoteCollectionFailure with stable serialization and timestamp handling across research, runtime, and backtest paths.
CLOB validation and failure emission
rust_hft/prediction-markets/crates/ploy-market-data/src/feeds.rs
Validates snapshots and price changes, rejects stale or invalid timestamps, propagates websocket failures, and emits structured failures before empty quotes.
Recorded quote classification
rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/recorded.rs
Classifies quote collection results in NDJSON logs and suppresses only synthetic empty quotes matching recorded failures.
Mission snapshot references
rust_hft/prediction-markets/config/research_missions/polymarket-*-5m.example.json
Updates the BTC and SOL research mission search_policy_snapshot_id values.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClobWebSocket
  participant ClobBookState
  participant MarketUpdateChannel
  participant RecordingFeed
  ClobWebSocket->>ClobBookState: Validate book and price changes
  ClobBookState-->>ClobWebSocket: Return quote update or error
  ClobWebSocket->>MarketUpdateChannel: Emit QuoteCollectionFailure
  ClobWebSocket->>MarketUpdateChannel: Emit empty Quote events
  MarketUpdateChannel->>RecordingFeed: Record quote updates
  RecordingFeed->>RecordingFeed: Classify outcomes and suppress matching synthetic empties
Loading

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: recording Polymarket quote collection outcomes.
Description check ✅ Passed The description covers the required sections and key intent; the optional scope-exception section is omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-quote-completeness-220

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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.

@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: 79e9f930cf

ℹ️ 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".

&& bid_levels.is_empty()
&& ask_levels.is_empty()
{
return None;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the fail-closed quote in replay tapes

When the WebSocket disconnects after publishing a valid book, spawn_clob_ws_quote_feed_until forwards a failure followed by an empty quote, but this return removes the empty quote from the tape. I checked RecordedFeed and SimulatedExecutor::observe_market_update: replay emits the failure as-is, while the executor and strategies clear cached liquidity only for an empty MarketUpdate::Quote, not for QuoteCollectionFailure. Consequently, live execution fails closed but replay retains the last executable quote and can produce fills or research results that were impossible live; preserve an equivalent empty update in replay or make the failure deterministically clear the book during replay.

Useful? React with 👍 / 👎.

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