Query editor
with position_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,case when 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_bnb.Pool_evt_OpenPositionwhere positionSize <> 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_bnb.Pool_evt_ClosePosition c left 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), volumes as (select date_trunc('day', evt_block_time) as dt,round(sum(case when trading_pair = 'BTCUSD' then volume else 0 end), 0) as btc_volume,round(sum(case when trading_pair = 'ETHUSD' then volume else 0 end), 0) as eth_volume,round(sum(case when trading_pair = 'BNBUSD' then volume else 0 end), 0) as bnb_volume,round(sum(volume), 0) as total_volumefrom unigroup by date_trunc('day', evt_block_time))select dt as "Date", btc_volume as "BTCUSD", eth_volume as "ETHUSD", bnb_volume as "BNBUSD", round(sum(total_volume) over(order by dt rows between unbounded preceding and current row), 0) as "Cumulative Trading Volume" --+ 6431183.2250602,from volumes-- select date_trunc('day', evt_block_time) as dt, trading_pair, round(sum(volume),0) as volume-- from uni-- group by date_trunc('day', evt_block_time) , trading_pair