Query editor
with last_price as (select token_bought_address, amount_usd / token_bought_amount as token_pricefrom dex.tradeswhere token_bought_address = 0x046EeE2cc3188071C02BfC1745A6b17c656e3f3dand block_time > now() - interval '7' dayorder by block_time desclimit 1),tokens_traded as (select taker, count(distinct(token_bought_address)) as tokens_tradedfrom dex.tradeswhere block_time > now() - interval '30' daygroup by taker)select dex_trades.taker,sum(tokens_bought) as bought_tokens,sum(tokens_sold) as sold_tokens,sum(profit) as realized_pnl,(sum(tokens_bought) - sum(tokens_sold)) * avg(last_price.token_price) as unrealized_pnl,count(*) as number_of_trades,sum(profit) + ((sum(tokens_bought) - sum(tokens_sold)) * avg(last_price.token_price)) as pnl,avg(tokens_traded) as token_tradedfrom (select taker, token_bought_amount as tokens_bought, 0 as tokens_sold, -amount_usd as profitfrom dex.tradeswhere token_bought_address = 0x046EeE2cc3188071C02BfC1745A6b17c656e3f3dunion allselect taker, 0 as tokens_bought, token_sold_amount as tokens_sold, amount_usd as profitfrom dex.tradeswhere token_sold_address = 0x046EeE2cc3188071C02BfC1745A6b17c656e3f3d) as dex_tradesjoin last_priceon last_price.token_bought_address = 0x046EeE2cc3188071C02BfC1745A6b17c656e3f3dleft join tokens_tradedon tokens_traded.taker = dex_trades.takergroup by dex_trades.takerhaving sum(tokens_bought) > sum(tokens_sold) and count(*) < 100 and avg(tokens_traded) > 0order by pnl desclimit 1000