cypherLUNA liquidations-inducing drawdowns and recovery
Updated 2022-04-13Copy Reference Fork
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
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