Query editor
-- POLYMARKET COPY TRADING LEADERBOARD - 30 DAY FOCUS-- Simplified to focus only on 30-day performance metricsWITH current_prices AS (-- Get the most recent price for each market/outcomeSELECTquestion,token_outcome_name,price as current_price,block_time as price_timestampFROM (SELECTquestion,token_outcome_name,price,block_time,ROW_NUMBER() OVER (PARTITION BY question, token_outcome_nameORDER BY block_time DESC) as rnFROM polymarket_polygon.market_tradesWHERE block_time >= current_timestamp - interval '30' dayAND neg_risk = false) rankedWHERE rn = 1),deduplicated_trades AS (-- Deduplicate trades and assign to correct traderSELECT DISTINCTtx_hash,taker as trader_address,block_time,CAST(block_time AS DATE) as trade_date,event_market_name,question,token_outcome_name,action,price,shares,amount,fee,-- Correct cash flow: negative when spending, positive when receivingCASEWHEN action = 'BUY' THEN -(amount + fee)ELSE (amount - fee)END as cash_flow,-- Share delta: positive when buying, negative when sellingCASEWHEN action = 'BUY' THEN sharesELSE -sharesEND as share_deltaFROM polymarket_polygon.market_tradesWHERE block_time >= current_timestamp - interval '30' dayAND neg_risk = falseAND shares > 0.01AND maker != taker