winnie-fsBONK - [trading] volume by price copy
    Updated 2023-05-01
    -- forked from marqu / BONK - [trading] volume by price @ https://flipsidecrypto.xyz/marqu/q/bonk-trading-cvd-BKUQHm

    with

    trading as (

    select

    block_timestamp,
    coalesce(close,
    lag(close) ignore nulls over (order by recorded_hour)
    ) as price,
    ifnull(swap_from_amount * p1.close, 0) as usd,
    'sell' as label_action

    from solana.core.fact_swaps swaps
    left join solana.core.ez_token_prices_hourly p1
    on swaps.swap_from_mint = p1.token_address
    and date_trunc('hour', swaps.block_timestamp) = p1.recorded_hour
    where succeeded
    and swap_from_mint = 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263'
    and not swap_to_mint in ('o1Mw5Y3n68o8TakZFuGKLZMGjm72qv4JeoZvGiCLEvK') -- $COPE bugged prices
    and block_timestamp ::date > current_date() - interval '{{months}} months'

    union all

    select

    block_timestamp,
    coalesce(close,
    lag(close) ignore nulls over (order by recorded_hour)
    ) as price,
    ifnull(swap_to_amount * p2.close, 0) as usd,
    'buy' as label_action

    from solana.core.fact_swaps swaps
    Run a query to Download Data