nitsLUNA Drawdown
    Updated 2022-04-18
    with min_prices as
    (SELECT date(block_timestamp) as day, min(price_usd) as min_price
    from terra.oracle_prices
    where symbol = 'LUNA' and block_timestamp >= '2021-03-24'
    GROUP by 1 ),
    max_prices as
    (SELECT date(block_timestamp) as date, max(price_usd) as max_price
    from terra.oracle_prices
    where symbol = 'LUNA' and block_timestamp >= '2021-03-24'
    GROUP by 1 ),
    max_prices1 as
    (SELECT date(block_timestamp) as date1, max(price_usd) as max_price_data
    from terra.oracle_prices
    where symbol = 'LUNA'and block_timestamp >= '2021-03-24'
    GROUP by 1 ),
    liq as
    (SELECT date(block_timestamp) as day_, sum(LIQUIDATED_AMOUNT_USD) as total_amt
    from anchor.liquidations
    GROUP by 1 ),
    liq1 as
    (SELECT date(block_timestamp) as _day_, sum(LIQUIDATED_AMOUNT_USD) as total_amt_
    from anchor.liquidations
    GROUP by 1 ),
    all_data as
    ( SELECT * from
    (SELECT * from
    (SELECT * from liq
    inner join liq1
    on day_ = _day_ +1 )
    where total_amt > 500000)
    inner join max_prices
    on date = day_),
    all_data1 as
    (SELECT * from all_data
    right join max_prices1
    on date1 = date) ,
    Run a query to Download Data