Deebs-DeFi-j9fRbzETH Buy and Sell
Updated 2023-06-14
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
WITH buys AS(
select
date_trunc('hour',BLOCK_TIMESTAMP) AS DATE,
SUM(amount_out) AS total_bought
from ethereum.core.ez_dex_swaps
WHERE DATE BETWEEN {{start_date}} AND {{end_date}}
AND token_out=lower('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
group by 1
),
sells AS(
select
date_trunc('hour',BLOCK_TIMESTAMP) AS DATE,
SUM(amount_in) AS total_sold
from ethereum.core.ez_dex_swaps
WHERE DATE BETWEEN {{start_date}} AND {{end_date}}
AND token_in=lower('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
group by 1
),
price AS(
select
date_trunc('hour', HOUR) AS DATE,
Symbol,
avg(price) as price
from crosschain.core.ez_hourly_prices
WHERE DATE BETWEEN {{start_date}} AND {{end_date}}
AND TOKEN_ADDRESS=lower('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
group by 1,2
)
SELECT
b.date,
b.total_bought,
s.total_sold,
p.price
FROM buys b
LEFT JOIN sells s USING(DATE)
LEFT JOIN price p USING(DATE)
Run a query to Download Data