fix(polymarket_polygon): is_taker_side flag + apply filter in ohlcv to fix volume double-counting#9684
Conversation
Polymarket's CLOB contracts emit two OrderFilled events per match (maker leg + taker leg), each carrying the full fill amount. A naive SUM(amount) over market_trades double-counts volume by ~2x, which is how every consumer of these spells has been reading volume to date. This change: 1. market_trades_raw / market_trades: add is_taker_side BOOLEAN. TRUE on the taker leg of each match. Predicate: taker IN (V1 CTF 0x4bfb...82e, V1 NegRisk 0xc5d5...80a, V2 CTF 0xe111...996b, V2 NegRisk 0xe222...0f59). All rows preserved so users who want the raw event stream still have it. 2. ohlcv_hourly: filter to is_taker_side=true at the base CTE. volume_usd, volume_contracts, trade_count halve on Polymarket; open/high/low/close/vwap unchanged (price is per-trade, symmetric). This brings the OHLCV table in line with Polymarket's own published methodology. Validation: cell-by-cell match against the Polymarket-authored reference query 6899861 across 17 months (Jan 2025 to May 2026). Deltas are in 1e-7 floating-point range. Notional shares for Apr 2026 = 9.0086B, matches the publicly-cited "$9 billion notional" figure exactly. Methodology source: https://www.paradigm.xyz/2025/12/polymarket-volume-is-being-double-counted Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
PR SummaryMedium Risk Overview Updates Reviewed by Cursor Bugbot for commit 119aaa1. Configure here. |
Drop the methodology comment block in market_trades_raw and the inline comment on the ohlcv_hourly filter. PR description carries the WHY. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…untime The CI for this PR cancels at the 90-minute timeout because the temp schema has no prior state, so is_incremental() is false and the modified models scan the full historical OrderFilled history. Add an else branch on each is_incremental() guard that floors the initial build at the last 7 days. Prod incremental runs are unaffected (the is_incremental() branch still uses the existing DBT_ENV_INCREMENTAL_TIME predicate). - market_trades_raw.sql: 3 union legs (V1 CTF, V1 NegRisk, V2) - ohlcv_hourly.sql: base CTE and final SELECT Verified locally with `dbt --warn-error compile`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…und CI runtime" This reverts commit c566411.
Summary
Polymarket's CLOB contracts emit two
OrderFilledevents per match (one for the maker leg, one for the taker leg), each carrying the full fill amount. NaiveSUM(amount)overpolymarket_polygon.market_tradestherefore over-reports volume by ~2x. This is the double-counting documented by Paradigm in Dec 2025.This PR:
market_trades_raw+market_trades: adds a new columnis_taker_side BOOLEAN. TRUE on the taker leg of each match. All rows preserved (no row-count change), so users who want the raw OrderFilled stream still have it.ohlcv_hourly: filters tois_taker_side = trueat the base CTE.volume_usd,volume_contracts,trade_count,vwaphalve to Polymarket-canonical values.open/high/low/closeunchanged (price is per-trade, symmetric across both legs).Predicate:
taker IN (V1 CTF 0x4bfb...82e, V1 NegRisk 0xc5d5...80a, V2 CTF 0xe111...996b, V2 NegRisk 0xe222...0f59).Validation
Cell-by-cell match against the Polymarket-authored reference query 6899861 across 17 months (Jan 2025 to May 2026). Deltas are floating-point noise (1e-7 range). Sample:
is_taker_sidefilterThe 9.0086B April 2026 notional matches the publicly-cited "Polymarket posted $9 billion in notional terms" figure exactly.
Verification query: 7538562.
Downstream impact
polymarket_polygon.market_tradespolymarket_polygon.ohlcv_hourlyvolume_usd,volume_contracts,trade_counthalve. Prices unchanged.prediction_markets.ohlcv_hourly(curated-data)prediction_markets.trades(curated-data)is_taker_side. All Kalshi rows will carryis_taker_side = TRUE(Kalshi has no double-counting) so the filter can be applied uniformly across venues.market_trades.amountwithout filterTest plan
dbt parse --warn-error-options error:allclean locally (matches CI's exact flag set).dbt compileclean formarket_trades_raw,market_trades,ohlcv_hourly.🤖 Generated with Claude Code