Skip to content
Dune Analytics

@hagaetc / Monthly DEX volume grouped by year

Monthly DEX volume grouped by year

Loading
 

About queries and results

Dune Analytics lets you explore, create, and share Ethereum analytics. You can find an endless amount of great queries and dashboards on Dune.

We have decoded Ethereum smart contract data so you can do powerful analysis with simple SQL queries and visualise the query results into beautiful graphs.

Dune Analytics is free for everyone forever. If you want extra features like private queries, export your results and more check out our Pro plan.

SQL query

1WITH prices AS (                                                                                       
2    SELECT date_trunc('day', minute) as day,                                                         
3        contract_address,                                                                              
4        AVG(price) as price                                                                                
5    FROM prices.usd                                                                                    
6    WHERE minute > '2019-01-01'
7    GROUP BY 1, 2                                                                                      
8)
9
10
11SELECT                      
12    date_part('year', block_time) AS year,
13    date_part('month', block_time) AS month,
14    SUM(COALESCE(
15            usd_amount,                 -- Use USD amount directly if available in dex.trades table
16            token_a_amount * a.price,   -- If no USD amount multiply token A with USD price 
17            token_b_amount * b.price    -- Else multiply token B with USD price
18        )) as usd_volume                                                                                  
19FROM dex."trades" t                                                                             
20LEFT JOIN prices a ON date_trunc('day', block_time) = a.day AND token_a_address = a.contract_address 
21LEFT JOIN prices b ON date_trunc('day', block_time) = b.day AND token_b_address = b.contract_address 
22WHERE block_time >= '2019-01-01'
23--AND block_time < date_trunc('month', Now()) -- This line can be added in case you only want to see full months
24GROUP BY 1, 2

SQL query results

Loading