Query editor
withposition_open as (select*,cast(json_query(position, 'lax $.initMargin') as uint256) as init_margin,cast(json_query(position, 'lax $.extraMargin') as uint256) as extra_margin,cast(json_query(position, 'lax $.leverage') as uint256) as leverage,json_value(position, 'lax $.owner') as owner,casewhen json_value(position, 'lax $.tradingPairId') = '0x9317fdc1187cd642023ce08ab1c6f9b51f60ee9677f05deb46f6080e26c55a14' then 'BTCUSD'when json_value(position, 'lax $.tradingPairId') = '0xd02ccd288a82d94573c88f153f9918f57695561788490de870e021d484c73bbf' then 'ETHUSD'else 'BNBUSD' end as trading_pair,cast(json_query(position, 'lax $.initMargin') as uint256) * cast(json_query(position, 'lax $.leverage') as uint256) / pow(10, 18) as open_volume_busdfrom borabora_v3_bnb.Pool_evt_OpenPositionwherepositionSize <> cast(0 as uint256) or positionId in (select positionId from borabora_bnb.Pool_evt_ExecPreBill) -- excluding limit orders that are not executed), position_close as (select c.*,cast(json_value(closeInfo, 'lax $.positionId') as uint256) as positionId,(o.init_margin + o.extra_margin) * o.leverage / pow(10, 18) as close_volume_busd,o.owner,o.trading_pair,json_value(closeInfo, 'lax $.isProfit') as isProfit,cast(json_query(closeInfo, 'lax $.pnl') as uint256) as pnlfrom borabora_v3_bnb.Pool_evt_ClosePosition cleft join position_open o on cast(json_value(c.closeInfo, 'lax $.positionId') as uint256) = o.positionId), uni as (select evt_block_time, open_volume_busd as volume, trading_pair, positionId, 'open' as "type", owner from position_openunion allselect evt_block_time, close_volume_busd as volume, trading_pair, positionId, 'close' as "type", owner from position_close)selectround(sum(volume) + 27105378 ,0) as total_volume, -- + 6431183.2250602casewhen round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '24' hour), 0) is null then 0else round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '24' hour), 0) end as one_day_volume,round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '7' day), 0) as seven_day_volume,round(sum(volume) filter (where "type" = 'close') * 0.0004 + 22497, 0) as total_trading_fees, -- + 1824casewhen round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '24' hour) * 0.0004, 0) is null then 0else round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '24' hour) * 0.0004, 0) end as one_day_trading_fees,round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '7' day) * 0.0004, 0) as seven_day_trading_fees,count(distinct owner) + 2128 as total_unique_users, -- +829count(distinct owner) filter(where evt_block_time >= current_timestamp - interval '24' hour) as one_day_unique_users,count(distinct owner) filter(where evt_block_time >= current_timestamp - interval '7' day) as seven_day_unique_users,count(distinct owner) filter(where owner not in (select owner from uni where evt_block_time < current_timestamp - interval '24' hour)) as one_day_new_usersfrom uni