Query editor
-- Method 1: Inner join all IncreasePositions and only show pair trades opened, discounting volumes from all other non-IncreasePosiions-- e.g. Long BTC / Short ETH --> BTC price / ETH price = BTC/ETH executed price-- Method 2:WITH user_positions AS -- ID(SELECT contract_address, evt_tx_hash, evt_index, evt_block_time,account,collateralToken,collateralDelta/1e30 AS collateralDelta,fee/1e30 AS fee,isLong,price/1e30 AS price,indexToken,IF(event = 'DecreasePosition', -(sizeDelta/1e30), sizeDelta/1e30) AS sizeDelta,"key",eventFROM (SELECT *, 'IncreasePosition' AS event FROM gmx_arbitrum.Vault_evt_IncreasePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03'UNION ALLSELECT *, 'DecreasePosition' AS event FROM gmx_arbitrum.Vault_evt_DecreasePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03')WHERE account IN (SELECT DISTINCT BYTEARRAY_SUBSTRING(topic2, 13, 20) AS adapter -- has leading zeros in address so can't use LTRIMFROM arbitrum.logsWHERE topic0 = 0xeccedcc6368d8acccba7ee32f84daeecf7350e56a501ad1438a1b417053c0fd0 -- PositionOpened--AND contract_address = 0x1DDCa7eaec57d24561e3Ba9A5A0c043868127018)ORDER BY evt_block_time DESC, evt_index DESC),position_details AS -- IDUC: user positions + position details(SELECT id.*,uc.averagePrice/1e30 AS averagePrice,uc.collateral/1e30 AS collateral,uc.entryFundingRate,uc.realisedPnl/1e30 AS realisedPnl,uc.reserveAmount,uc.size/1e30 AS size,uc.event AS uc_eventFROM user_positions idINNER JOIN (SELECT *, 'UpdatePosition' AS event FROM gmx_arbitrum.Vault_evt_UpdatePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03'UNION ALLSELECT *, 'ClosePosition' AS event FROM gmx_arbitrum.Vault_evt_ClosePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03') ucON id.evt_tx_hash = uc.evt_tx_hashAND id."key" = uc."key"ORDER BY id.evt_block_time DESC, id.evt_index DESC),liquidations AS(SELECT contract_address, evt_tx_hash, evt_index, evt_block_time, account,collateralToken, NULL AS collateralDelta, NULL AS fee,isLong, markPrice/1e30, indexToken, -(size/1e30) AS sizeDelta,