Query editor
-- approx. PnL (last 30 days)with gmx_perps as (selectdate_trunc('day', block_time) as dt,virtual_asset as position_asset,underlying_asset as position_asset2,market as pair,market_address as pool_address,trade as trade_type,trader,tx_to as to_pool,tx_from as from_pool,volume_usd,fee_usd,margin_usdfrom gmx_arbitrum.perpetual_tradesWHERE block_time >= NOW() - INTERVAL '30' DAY),open_positions as (select dt,trader,pair,position_asset,position_asset2,pool_address,sum(case when trade_type IN ('open-long', 'close-short') then volume_usd else 0 end) as long_volume_usd,sum(case when trade_type IN ('open-short', 'close-long') then volume_usd else 0 end) as short_volume_usd,max(case when trade_type IN ('open-long', 'open-short') then margin_usd end) as entry_margin_usd,max(case when trade_type IN ('open-long', 'open-short') then fee_usd end) as entry_fee_usdfrom gmx_perpsWHERE trade_type IN ('open-long', 'open-short')group by dt, trader, pair, position_asset, position_asset2, pool_address),closed_positions as (select dt,trader,pair,position_asset,position_asset2,pool_address,sum(case when trade_type IN ('close-long', 'open-short') then volume_usd else 0 end) as long_volume_usd,sum(case when trade_type IN ('close-short', 'open-long') then volume_usd else 0 end) as short_volume_usd,sum(case when trade_type = 'close-long' then volume_usd when trade_type = 'open-short' then -volume_usd else 0 end) as closed_long_volume_usd,sum(case when trade_type = 'close-short' then volume_usd when trade_type = 'open-long' then -volume_usd else 0 end) as closed_short_volume_usd,max(case when trade_type IN ('close-long', 'close-short') then margin_usd end) as exit_margin_usd,max(case when trade_type IN ('close-long', 'close-short') then fee_usd end) as exit_fee_usdfrom gmx_perpsWHERE trade_type IN ('close-long', 'close-short')group by dt, trader, pair, position_asset, position_asset2, pool_address),position_trades as (select open_positions.dt as open_dt,closed_positions.dt as close_dt,open_positions.trader,open_positions.pair,open_positions.position_asset,open_positions.position_asset2,open_positions.pool_address,