Query editor
WITH markets_data AS (SELECTCASEWHEN blockchain = 'avalanche_c' THEN 'Avalanche'ELSE INITCAP(blockchain)END AS chain, market, market_name, CASEWHEN blockchain = 'avalanche_c' THEN CONCAT('Avalanche',' ', market_name)ELSE CONCAT(INITCAP(blockchain),' ', market_name)END AS market_longFROM gmx_v2.markets_data)SELECTtime, IF(pnl > 0, pnl, NULL) as green_pnl, IF(pnl < 0, pnl, NULL) as red_pnl, profit_pnl, loss_pnl, total_pnl, total_profit_pnl, total_loss_pnl, total_pnl/1e6 as total_pnl_format, daily_pnl/1e3 as daily_pnl_format, weekly_pnl/1e6 as weekly_pnl_formatFROM (SELECT-- DISTINCT t1.chain, t1.market, md.market_longdate_trunc('day', time) as time, SUM(pnl) as pnl, SUM(if(pnl > 0, pnl, 0)) as profit_pnl, SUM(if(pnl < 0, pnl, 0)) as loss_pnl, SUM(sum(pnl)) OVER (ORDER BY date_trunc('day', time)) as total_pnl, SUM(sum(IF(time >= NOW() - INTERVAL'1' DAY, pnl, 0))) OVER (ORDER BY date_trunc('day', time)) as daily_pnl, SUM(sum(IF(time >= NOW() - INTERVAL'7' DAY, pnl, 0))) OVER (ORDER BY date_trunc('day', time)) as weekly_pnl, SUM(sum(IF(pnl >= 0, pnl, 0))) OVER (ORDER BY date_trunc('day', time)) as total_profit_pnl, SUM(sum(IF(pnl < 0, pnl, 0))) OVER (ORDER BY date_trunc('day', time)) as total_loss_pnlFROM (SELECTblock_time AS time, market, base_pnl_usd AS pnl, 2 AS version, CASEWHEN blockchain = 'avalanche_c' THEN 'Avalanche'ELSE INITCAP(blockchain)END AS chainFROM gmx_v2.position_decrease-- UNION ALL-- SELECT date_trunc('day', evt_block_time) as time, (realisedPnl * 1e-30) as pnl-- , 1 as version-- FROM gmx_arbitrum.Vault_evt_ClosePosition-- UNION ALL-- SELECT date_trunc('day', evt_block_time) as time, -(collateral*1e-30) as pnl-- , 1 as version-- FROM gmx_arbitrum.Vault_evt_LiquidatePosition