Query editor
with ton_prices as ( -- get price of TON for each day to estimate USD valueselectdate_trunc('day', minute) as block_date, avg(price) as pricefrom prices.usdwhere trueand symbol = 'TON' and blockchain is null group by 1)select date_trunc('month', block_date) as month, pool_name,sum(size_delta * trade_price /1e18 * casewhen pool_name like 'TON%' then 1/1e9 * price -- TON has 9 decimals and required to be converted to #else 1/1e6 -- USDT has 6 decimalsend) as volume_usdfrom test_schema.git_dunesql_9cbe339_tradoor_ton_perp_position_changejoin ton_prices using(block_date)where 1 = 1and block_date > timestamp '2025-01-01'group by 1 , 2