Query editor
with smartTraders as (select s.address as address, v.name as name from query_2608904 sjoin labels.average_trade_values von s.address=cast(v.address as varbinary)-- where v.name != '<=$400 avg. DEX trade value'),ethPrice as (SELECT date_trunc('day', minute) as time, avg(price) as priceFROM prices.usd WHERE symbol = 'ETH'group by 1),sellers as (select date_trunc('day', d.block_date) as time, token_sold_symbol,sum(amount_usd) as volume_soldfrom dex.trades d join smartTraders s on s.address= cast(d.tx_from as varbinary)WHERE d.block_date > now() - interval '90' dayand NOT contains(array['WETH', 'ETH', 'USDC', 'USDT', 'BUSD', 'DAI', 'TUSD', 'EURS', 'MIM', 'sETH','fxETH', 'stETH', 'cbETH', 'agEUR', 'USH', 'wstETH', 'FRAX', 'sUSD', 'crvFRAX', 'USDC.e'], token_sold_symbol)and amount_usd >= 500group by 1, 2),buyers as (select date_trunc('day', d.block_date) as time, token_bought_symbol,sum(amount_usd) as volume_boughtfrom dex.trades d join smartTraders s on s.address=cast(d.tx_from as varbinary)WHERE d.block_date > now() - interval '90' dayand not contains(array['WETH', 'ETH', 'USDC', 'USDT', 'BUSD', 'DAI', 'TUSD', 'EURS', 'MIM', 'sETH','fxETH', 'stETH', 'cbETH', 'agEUR', 'USH', 'wstETH', 'FRAX', 'sUSD', 'crvFRAX', 'USDC.e'], token_bought_symbol)and amount_usd >= 500group by 1, 2),merged as (select b.time as time, volume_bought, volume_sold, token_bought_symbol, volume_bought - volume_sold as netfrom buyers b join sellers s on b.time = s.time and b.token_bought_symbol=s.token_sold_symbolwhere volume_bought > 50000 or volume_sold > 50000)select time, volume_sold, volume_bought, volume_bought - volume_sold as net_volume, token_bought_symbol, net from merged--select * from buyers where volume_bought > 100000 order by time, volume_bought--select * from sellers where volume_sold > 100000 order by time, volume_sold