Query editor
-- Estimated Daily Open Interest (OI) = Sum of all open positions (as of midnight UTC) * last price traded or outcome if market closed-- Note: Active & inactive markets are included (i.e. unredeemed winnings are counted).WITH positions_filtered AS (SELECT day, token_id, balanceFROM polymarket_polygon.positionsWHERE address != 0xa5ef39c3d3e10d0b270233af41cac69796b12966 -- ignore, protocol addressAND day >= DATE_TRUNC('day', now() - INTERVAL '30' DAY)AND day <= DATE_TRUNC('day', now() - INTERVAL '1' DAY)AND balance > 0 -- No balance, then $0 OI, remove to make join faster),prices_filtered AS (SELECT *FROM(SELECTday,mp.token_id,case when (market_closed = TRUE) and (day >= DATE_TRUNC('day', market_closed_date)) then outcome_result else price end final_priceFROM polymarket_polygon.market_prices_daily mpINNER JOIN dune.polymarket.token_metadata m -- using the token data Polymarket updates dailyON mp.token_id = m.token_idAND day >= DATE_TRUNC('day', now() - INTERVAL '30' DAY)AND day <= DATE_TRUNC('day', now() - INTERVAL '1' DAY))WHERE final_price > 0 -- $0 price, then $0 OI, remove to make join faster)SELECTp.day as dt,SUM(p.balance * dp.final_price) AS dune_oi_utcFROM positions_filtered pINNER JOIN prices_filtered dpON dp.token_id = p.token_idAND dp.day = p.dayGROUP BY 1ORDER BY 1 desc