feat(polymarket): add maker_side and taker_side to market_trades - #9703
Conversation
Requested by BAM (CUR2-2551) to reconstruct wallet positions over time without scraping the Polymarket API. Each fill carries a BUY/SELL direction; consumers read the side matching whichever address (maker or taker) is their wallet, with no inversion logic. Derivation: - V1 (CTFExchange + NegRiskCtfExchange): makerAssetId = 0 means the maker paid USDC for outcome tokens, so maker_side = BUY (else SELL). - V2 (CTFExchange V2, pUSD): the OrderFilled event carries an explicit side enum, 0 = BUY, 1 = SELL. - taker_side is always the inverse of maker_side. Verification: - Tier 1: dbt --warn-error compile clean on both models. - Tier 2: distribution on 24h windows confirms both branches fire on every source (V1 CTF 5.9M BUY / 0.93M SELL, V1 NegRisk 1.0M / 0.51M, V2 5.4M / 0.94M), no NULLs, no other values. Tests: not_null + accepted_values(['BUY','SELL']) on both columns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PR SummaryLow Risk Overview Derivation is implemented in Reviewed by Cursor Bugbot for commit 1d1bebd. Configure here. |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1d1bebd. Configure here.
Summary
Adds
maker_sideandtaker_side('BUY'/'SELL', always opposite) topolymarket_polygon.market_trades. Requested by BAM (CUR2-2551) to reconstruct wallet positions over time. The Polymarket/tradesAPI exposes a per-walletside; this surfaces the same semantic at the spell layer so consumers don't have to scrape or maintain their own derivation.Derivation
CTFExchange_evt_OrderFilled+NegRiskCtfExchange_evt_OrderFilled):makerAssetId = 0means the maker paid USDC for outcome tokens, somaker_side = 'BUY'(otherwise'SELL').polymarket_v2_polygon.CTFExchange_evt_OrderFilled): the event carries an explicitsideenum,0 = BUY,1 = SELL.taker_sideis the inverse ofmaker_sideby construction.Usage
BUY=> +shares,SELL=> -shares. No inversion CASE required.Verification
Tier 1:
uv run dbt --warn-error compile --select polymarket_polygon_market_trades polymarket_polygon_market_trades_rawclean.Tier 2 invariants on 194M production rows (last 30 days):
Both branches fire on every source (24h window):
Cross-platform check against the Polymarket
/tradesAPI: 8 distinct tx_hashes / 10 OrderFilled events for a sample wallet, 10/10 match between our derived(maker_side, taker_side)and the API'sside. Two trades emit both legs and the derivation produces the correct side for the wallet on each leg.Note on observed distribution: maker_side skews ~85% BUY on production data. This is genuine Polymarket microstructure (LP rewards favor bid posting; position opens often go via
PositionSplitminting rather than the orderbook; sells tend to sweep multiple resting bids). Not a derivation artifact; verified by independently filtering eachis_taker_sideleg.Tests
not_null+accepted_values(['BUY','SELL'])on both columns. Existingis_taker_sideunchanged.Test plan
market_trades_raw+market_trades, then notify BAM in the existing email thread to validate against their Snowflake shareLinear
CUR2-2551