Query editor
WITHcalendar AS (SELECT dayFROM UNNEST(sequence(date_add('day', -CAST({{days}} AS bigint), current_date), current_date)) AS t(day)),assets(asset) AS (VALUES ('LC'), ('FCO')),trades AS (SELECTblock_date AS day,block_time,tx_hash,tx_from,CASEWHEN token_bought_address = 0xe7ED99DDc65Ce315F187ac9CCdf59576E89DD82EOR token_sold_address = 0xe7ED99DDc65Ce315F187ac9CCdf59576E89DD82E THEN 'LC'ELSE 'FCO'END AS asset,CASEWHEN token_bought_address IN (0xe7ED99DDc65Ce315F187ac9CCdf59576E89DD82E,0xcD1829e826249f41a5Cb434Bf2d25C3D5eA78eC0) THEN amount_usd / NULLIF(token_bought_amount, 0)ELSE amount_usd / NULLIF(token_sold_amount, 0)END AS price_usd,amount_usd,CASE WHEN token_bought_address IN (0xe7ED99DDc65Ce315F187ac9CCdf59576E89DD82E,0xcD1829e826249f41a5Cb434Bf2d25C3D5eA78eC0) THEN amount_usd ELSE 0 END AS buy_volume_usd,CASE WHEN token_sold_address IN (0xe7ED99DDc65Ce315F187ac9CCdf59576E89DD82E,0xcD1829e826249f41a5Cb434Bf2d25C3D5eA78eC0) THEN amount_usd ELSE 0 END AS sell_volume_usdFROM dex.tradesWHERE blockchain = 'bnb'AND project = 'pancakeswap'AND block_month >= date_trunc('month', date_add('day', -CAST({{days}} AS bigint), current_date))AND block_date >= date_add('day', -CAST({{days}} AS bigint), current_date)AND project_contract_address IN (0xAaDf6272ba63E89926B691030143437996467E04,0x2925340Dd64472A71D32aa9Bec6176f541595d97)AND amount_usd > 0),daily AS (SELECTday,asset,max_by(price_usd, block_time) AS close_price_usd,MIN(price_usd) AS low_price_usd,MAX(price_usd) AS high_price_usd,SUM(amount_usd) AS volume_usd,SUM(buy_volume_usd) AS buy_volume_usd,SUM(sell_volume_usd) AS sell_volume_usd,COUNT(DISTINCT tx_hash) AS trades,COUNT(DISTINCT tx_from) AS tradersFROM trades