Created
September 20, 2024 09:21
-
-
Save vivekascoder/2738408c824219d98e45120afde4c048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE MATERIALIZED VIEW IF NOT EXISTS daily_volume AS | |
WITH parameters AS ( | |
SELECT | |
'0x9cdAA94733a682013Ff8AfD72BA59FB63619C98d' AS pool_addr, | |
EXTRACT(EPOCH FROM NOW() - INTERVAL '24 hours') AS last_time | |
), | |
combined AS ( | |
SELECT amount, "blockTimestamp", pool | |
FROM "AddLiquidity" | |
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters) | |
UNION ALL | |
SELECT amount, "blockTimestamp", pool | |
FROM "OpenLong" | |
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters) | |
UNION ALL | |
SELECT amount, "blockTimestamp", pool | |
FROM "OpenShort" | |
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters) | |
) | |
SELECT SUM(amount) AS daily_volume, pool from combined | |
group by pool; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment