cypherLUNA liquidations-inducing drawdowns and recovery
    Updated 2022-04-13
    with luna_price as (select
    date_trunc('day', block_timestamp) as date,
    avg(price_usd) as avg_price,
    min(price_usd) as min_price,
    max(price_usd) as max_price
    FROM terra.oracle_prices
    WHERE symbol = 'LUNA'
    and block_timestamp >= '2021-3-17'
    group by date),

    daily_liquidated as (select
    date_trunc('day', block_timestamp) as date,
    sum(liquidated_amount_usd) as total_liquidated
    from anchor.liquidations
    group by date
    ),

    price_and_liquidated as (select * from luna_price
    full outer join daily_liquidated using (date)),

    liquidation_days as (select * from price_and_liquidated
    where total_liquidated >= 10000000
    and date not in ('2021-5-23', '2022-1-22', '2022-1-27', '2022-1-28')
    order by date),

    recovery_days as (select
    date(l.date) as liquidation_date,
    date(min(p.date)) as recovery_date,
    datediff(day, l.date, recovery_date) as recovery_days

    from luna_price p, liquidation_days l
    where p.date > l.date
    and p.avg_price > l.avg_price
    group by l.date
    order by l.date),

    Run a query to Download Data