FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
finplot/finplot/examples/heatmap.py at master · robot-python/finplot · GitHub
robot-python
/
finplot
Public
forked from
highfestiva/finplot
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
finplot
/
finplot
/
examples
/
heatmap.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (24 loc) · 1.03 KB
Breadcrumbs
finplot
/
finplot
/
examples
/
heatmap.py
Copy path
File metadata and controls
29 lines (24 loc) · 1.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
import
finplot
as
fplt
import
pandas
as
pd
import
requests
# download, extract times and candles
url
=
'https://www.tensorcharts.com/tensor/bitmex/XBTUSD/heatmapCandles/15min'
data
=
requests
.
get
(
url
).
json
()
times
=
pd
.
to_datetime
([
e
[
'T'
]
for
e
in
data
])
candles
=
[(
e
[
'open'
],
e
[
'close'
],
e
[
'high'
],
e
[
'low'
])
for
e
in
data
]
df_candles
=
pd
.
DataFrame
(
index
=
times
,
data
=
candles
)
# extract volume heatmap as a PRICE x VOLUME matrix
orderbooks
=
[(
e
[
'heatmapOrderBook'
]
or
[])
for
e
in
data
]
prices
=
sorted
(
set
(
prc
for
ob
in
orderbooks
for
prc
in
ob
[::
2
]))
vol_matrix
=
[[
0
]
*
len
(
prices
)
for
_
in
range
(
len
(
times
))]
for
i
,
orderbook
in
enumerate
(
orderbooks
):
for
price
,
volume
in
zip
(
orderbook
[::
2
],
orderbook
[
1
::
2
]):
j
=
prices
.
index
(
price
)
vol_matrix
[
i
][
j
]
=
volume
df_volume_heatmap
=
pd
.
DataFrame
(
index
=
times
,
columns
=
prices
,
data
=
vol_matrix
)
# plot
fplt
.
create_plot
(
'BitMEX BTC 15m orderbook heatmap'
)
fplt
.
candlestick_ochl
(
df_candles
)
fplt
.
heatmap
(
df_volume_heatmap
,
filter_limit
=
0.1
,
whiteout
=
0.1
)
fplt
.
show
()
Back
|
FazBrowse Home
|
New Git URL