SocioAnalyticaspread (blitz)
Updated 2024-04-25
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
›
⌄
-- forked from spread (blitz) @ https://flipsidecrypto.xyz/edit/queries/e18a6bd8-e18b-44b8-93f3-7bd79944aab3
with asks as (
select
hour,
ticker_id,
product_id,
price,
volume,
row_number () over (partition by hour, ticker_id, product_id order by price asc) as rank
from blast.blitz.ez_market_depth_stats
where orderbook_side = 'asks'
)
,
bids as (
select
hour,
ticker_id,
product_id,
price,
volume,
row_number () over (partition by hour, ticker_id, product_id order by price desc) as rank
from blast.blitz.ez_market_depth_stats
where orderbook_side = 'bids'
)
select
a.hour,
a.ticker_id,
(ABS(a.price - b.price)) as spread,
((a.price+b.price)/2) as mid_price,
100 * spread / mid_price as percentage_spread
from asks a
join bids b on a.hour = b.hour and a.ticker_id = b.ticker_id and a.product_id = b.product_id
and a.rank = b.rank
QueryRunArchived: QueryRun has been archived