Query editor
-- NetNet · Daily Closing Prices — COIN / SPCX / MSFT / NET vs USDG-- Method: last trade of the day (max block_number*100000+evt_index), price = amount_usd / token_amount,-- across ALL dex venues on Robinhood chain where the token trades directly against USDG.-- This generalizes query 8224214's "last Sync event of day" approach: COIN and MSFT have NO Sync-emitting-- (v2-style) USDG pool at all — 100% of their liquidity is on Uniswap v3/v4 + other CL/DLMM venues, which-- emit Swap (sqrtPriceX96), not Sync. SPCX has a v2 Sync pool but it went dead 2026-08-07 (real SPCX volume-- moved to v3/v4). NET's canonical pool IS v2/Sync (matches 8224214). Using dex.trades last-trade-of-day-- uniformly for all 4 tokens keeps one method instead of forking per-token; sanity-checked against 8224214's-- own Sync-based close for NET: <0.3% divergence on every day except the current partial day.---- DATA QUALITY GATE: early bootstrap days (mostly COIN, 2026-07-03 to 2026-07-21; a couple of early MSFT/SPCX-- days) had <$100 total daily USDG-pair volume and produced nonsensical closes (e.g. COIN swinging from-- $0.0002 to $1,608 day-to-day on 1-20 dust trades). Below $100/day volume the "last trade" is not a reliable-- market price, so close_price_usdg is NULLed (but the row + trades_that_day/day_vol_usd are kept) on those-- days. Downstream joins should treat NULL close_price_usdg as "no reliable price available" for that token-day.with px as (selectblock_date as day,upper(case when upper(token_bought_symbol) = 'USDG' then token_sold_symbol else token_bought_symbol end) as token_symbol,case when upper(token_sold_symbol) = 'USDG' then amount_usd / nullif(token_bought_amount, 0)else amount_usd / nullif(token_sold_amount, 0) end as trade_price,amount_usd,block_number * 100000 + evt_index as ordfrom dex.tradeswhere blockchain = 'robinhood'and block_date >= date '2026-06-01'and amount_usd > 0and ((upper(token_bought_symbol) in ('COIN','SPCX','MSFT','NET') and upper(token_sold_symbol) = 'USDG')or (upper(token_sold_symbol) in ('COIN','SPCX','MSFT','NET') and upper(token_bought_symbol) = 'USDG'))),agg as (selectday,token_symbol,max_by(trade_price, ord) as raw_close_price_usdg,sum(amount_usd) as day_vol_usd,count(*) as trades_that_dayfrom pxgroup by 1, 2)selectday,token_symbol,case when day_vol_usd >= 100 then raw_close_price_usdg else null end as close_price_usdg,day_vol_usd,trades_that_day,(day_vol_usd < 100) as low_liquidity_dayfrom aggorder by token_symbol, day