Sbhn_NPeth swap activity
    Updated 2022-10-14
    WITH
    eth_price as (
    SELECT
    date_trunc('day',hour) as day,
    avg(price) as eth_price
    from ethereum.core.fact_hourly_token_prices
    where symbol='WETH' and hour >='2022-09-01'
    group by 1
    ),
    eth_dex as (
    SELECT
    date_trunc('day',block_timestamp) as day,
    sum(case when symbol_in='WETH' then amount_in end) as volume_in,
    sum(case when symbol_out='WETH' then amount_out end) as volume_out,
    avg(case when symbol_in='WETH' then amount_in end) as avg_volume_in,
    avg(case when symbol_out='WETH' then amount_out end) avg_volume_out,
    count(case when symbol_in='WETH' then 1 end) as swaps_in,
    count(case when symbol_out='WETH' then 1 end) as swaps_out
    from ethereum.core.ez_dex_swaps where (symbol_in='WETH' or symbol_out='WETH') and block_timestamp >='2022-09-01'
    and amount_in_usd<1e9 and amount_out_usd<1e9
    group by 1
    )
    SELECT
    x.day,
    volume_in,
    volume_out,
    volume_in-volume_out as net_volume ,
    avg_volume_in,
    avg_volume_out,
    swaps_in,
    swaps_out,
    swaps_in-swaps_out as net_swaps,
    eth_price
    from eth_dex x join eth_price y on x.day=y.DAY
    order by 1 asc
    Run a query to Download Data