binhachonLUNA & Drawdowns - Liquidation histogram
    Updated 2022-04-11
    with max_price as (
    select
    date_trunc('day', block_timestamp) as time,
    block_timestamp,
    price_usd as max_price,
    avg(price_usd) over (partition by time) as avg_price,
    row_number() over (partition by time order by price_usd desc) as rank
    from terra.oracle_prices
    where symbol = 'LUNA'
    qualify rank = 1
    ),
    min_price as (
    select
    time,
    max_price,
    avg_price,
    price_usd as min_price,
    100 * (max_price - min_price) / max_price as "% drop from the day's high"
    from (
    select
    time,
    max_price,
    avg_price,
    price_usd
    from terra.oracle_prices
    inner join max_price on (time = date_trunc('day', terra.oracle_prices.block_timestamp) and terra.oracle_prices.block_timestamp >= max_price.block_timestamp)
    where symbol = 'LUNA'
    )
    qualify row_number() over (partition by time order by price_usd) = 1
    ),
    LUNA_price as (
    select
    date_trunc('day', block_timestamp) as time,
    100 * (max(price_usd) - min(price_usd)) / max(price_usd) as "% drop from the week's high"
    from terra.oracle_prices
    where symbol = 'LUNA'
    Run a query to Download Data