Query editor
With buys AS (Selecttx_from as wallet,SUM(amount_usd) as amount_USD,SUM(token_bought_amount) as token_bought_amount,count (*) as countfrom dex.tradesWhere token_bought_address = 0xd85c31854c2B0Fb40aaA9E2Fc4Da23C21f829d46group by 1),sells AS (Selecttx_from as wallet,SUM(amount_usd) as amount_USD,SUM(token_sold_amount) as token_sold_amount,count (*) as countfrom dex.tradesWhere token_sold_address = 0xd85c31854c2B0Fb40aaA9E2Fc4Da23C21f829d46group by 1),price AS (Selectprice,timestampfrom prices.dayWhere contract_address = 0xd85c31854c2B0Fb40aaA9E2Fc4Da23C21f829d46AND timestamp = TRY_CAST('2025-08-06 00:00:00' AS TIMESTAMP)),T1 AS (SELECTCOALESCE(A.wallet, B.wallet) AS wallet,COALESCE(SUM(A.amount_USD), 0) AS amount_USD_bought,COALESCE(SUM(B.amount_USD), 0) AS amount_USD_sold,COALESCE(SUM(A.token_bought_amount), 0) AS token_USD_bought,COALESCE(SUM(B.token_sold_amount), 0) AS token_USD_sold,SUM(A.count + B.count) as countFROM buys AS AFULL JOIN sells AS BON A.wallet = B.walletgroup by 1)Selectwallet,count,price,amount_USD_bought,amount_USD_sold,(amount_USD_sold - amount_USD_bought) as realsied_PNL,(token_USD_sold - token_USD_bought)*price as unrealsied_PNLfrom T1cross Join priceWhere count < 30and (amount_USD_sold - amount_USD_bought) > 10000