Query editor
with token_buys as (selecttx_from, block_time, amount_usd, token_bought_amount as token_amountfrom dex.tradeswhere blockchain = 'robinhood'and block_date >= cast(now() - interval '100' day as date)and token_bought_address = {{token_address}}and amount_usd > 0), token_sells as (selecttx_from, block_time, amount_usd, token_sold_amount as token_amountfrom dex.tradeswhere blockchain = 'robinhood'and block_date >= cast(now() - interval '100' day as date)and token_sold_address = {{token_address}}and amount_usd > 0), buy_stats as (selecttx_from, min(block_time) as first_buy_time, count(*) as buy_count, sum(amount_usd) as total_buy_usd, sum(token_amount) as total_buy_tokensfrom token_buysgroup by 1), sell_stats as (selecttx_from, min(block_time) as first_sell_time, count(*) as sell_count, sum(amount_usd) as total_sell_usd, sum(token_amount) as total_sell_tokensfrom token_sellsgroup by 1), wallet_stats as (selectbuys.tx_from, buys.first_buy_time, buys.buy_count, buys.total_buy_usd, buys.total_buy_tokens, sells.first_sell_time, coalesce(sells.sell_count, 0) as sell_count, coalesce(sells.total_sell_usd, 0.0) as total_sell_usd, coalesce(sells.total_sell_tokens, 0.0) as total_sell_tokens, buys.total_buy_tokens - coalesce(sells.total_sell_tokens, 0.0) as net_position_tokens, coalesce(sells.total_sell_tokens, 0.0) / nullif(buys.total_buy_tokens, 0) as pct_sold, date_diff('hour',buys.first_buy_time,