Query editor
-- both ctfExchange and negriskCTFexcahnge consist of different transactions from different markets therefore total volumne include both exchangesWITHdates AS (WITH sequence_dates AS (SELECT sequence(cast(DATE_TRUNC('day', NOW()) - interval '{{Trailing Num Days}}' day as date),cast(DATE_TRUNC('day',NOW()) as date),interval '1' day) AS range)SELECT sequence_dates_unnested.rangeFROM sequence_datesCROSS JOIN unnest(sequence_dates.range) AS sequence_dates_unnested(range)),combined_exchanges_in_day AS (WITH combined_exchanges_within_range AS (SELECT-- note: this is in UTCevt_block_time as tx_time,SUM(-- if takerAssetID == 0, takerAmountfilled is the amount to be considered as it is the USDC, which is more accurate to measure acrossCASEWHEN TRY_CAST(makerAssetId AS VARCHAR) = '0' THEN TRY_CAST(makerAmountFilled AS DOUBLE)WHEN TRY_CAST(takerAssetId AS VARCHAR) = '0' THEN TRY_CAST(takerAmountFilled AS DOUBLE)END) / 1e6 AS volume_transactionFROM polymarket_polygon.CTFExchange_evt_OrderFilledWHERE evt_block_time >= (current_date - interval '{{Trailing Num Days}}' day)GROUP BY evt_block_timeUNIONSELECTevt_block_time as tx_time,SUM(CASEWHEN TRY_CAST(makerAssetId AS VARCHAR) = '0' THEN TRY_CAST(makerAmountFilled AS DOUBLE)WHEN TRY_CAST(takerAssetId AS VARCHAR) = '0' THEN TRY_CAST(takerAmountFilled AS DOUBLE)END) / 1e6 AS volume_transactionFROM polymarket_polygon.NegRiskCtfExchange_evt_OrderFilledWHERE evt_block_time >= (current_date - interval '{{Trailing Num Days}}' day)GROUP BY evt_block_time)SELECTDATE_TRUNC('day', tx_time) as day,SUM(volume_transaction) as daily_volumeFROMcombined_exchanges_within_rangeGROUP BYDATE_TRUNC('day', tx_time)), volume_in_week AS (SELECTday,SUM(daily_volume) as weekly_volumeFROM (SELECTdates.range AS day,COALESCE(SUM(combined_exchanges_in_day.daily_volume), 0) AS daily_volumeFROMdates