Query editor
with account_connection as (select distinct * from(select primaryAccount as account , subAccount from hmx_arbitrum.TradeService_evt_LogIncreasePosition)),pnl as (select ac.account as account, sum(coalesce(pnl.pnl,0))/1e30 as pnlfrom account_connection acleft join(select subAccount , sum(pnl) as pnl from((select subAccount, -sum(cast(usd as double)) as pnl from hmx_arbitrum.TradeHelper_evt_LogSettleUnRealizedPnlValuegroup by subAccount)union all(select subAccount, sum(cast(usd as double)) as pnl from hmx_arbitrum.TradeHelper_evt_LogReceivedUnRealizedPnlValue-- Manually removed as the profit corresponding to the trade was injected back to the HLP pool.where evt_tx_hash != 0x0c3fb1bd328fa7d08484bfd8b3cd946c048e860236fe1842a64536b5760393afgroup by subAccount))group by subAccount) pnlon ac.subAccount = pnl.subAccountgroup by ac.account)select row_number() over (order by pnl.pnl desc) as "rank", account, pnl.pnl as PnLfrom pnlorder by pnl desclimit 20