SniperBi3
Updated 2022-11-02Copy 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 Moving_Average_Base as (
select
date_trunc('day', block_timestamp) as date,
count(DISTINCT tx_id) as swap_cnt,
sum(from_amount/1e6) as Volume
from osmosis.core.fact_swaps
WHERE date >= CURRENT_DATE -100
and from_currency = 'uosmo'
group by 1
)
, Moving_Average as (
SELECT
date,
avg(swap_cnt) over (ORDER BY date ROWS BETWEEN 60 PRECEDING AND CURRENT ROW) as tx_swapped,
avg(Volume) over (ORDER BY date ROWS BETWEEN 60 PRECEDING AND CURRENT ROW) as amount_swapped
FROM Moving_Average_Base
)
,Moving_Average_60day as (
select *
from Moving_Average
where date = '2022-10-28'
)
, Base_Data as (
select
date_trunc('hour', BLOCK_TIMESTAMP) as date,
count(DISTINCT tx_id) as swap_cnt,
sum(from_amount/1e6) as Volume
from osmosis.core.fact_swaps
where block_timestamp::date = '2022-10-28'
and from_currency = 'uosmo'
group by 1
)
SELECT
*,
(select tx_swapped from Moving_Average_60day ) as Moving_Average_60day_osmo_tx_swap,
(select amount_swapped from Moving_Average_60day ) as Moving_Average_60day_osmo_vol_swap
Run a query to Download Data