FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
finplot/finplot/examples/embed.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
/
embed.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (51 loc) · 1.77 KB
Breadcrumbs
finplot
/
finplot
/
examples
/
embed.py
Copy path
File metadata and controls
63 lines (51 loc) · 1.77 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
import
finplot
as
fplt
from
functools
import
lru_cache
from
PyQt6
.
QtWidgets
import
QApplication
,
QGridLayout
,
QGraphicsView
,
QComboBox
,
QLabel
from
threading
import
Thread
import
yfinance
as
yf
app
=
QApplication
([])
win
=
QGraphicsView
()
win
.
setWindowTitle
(
'TradingView wannabe'
)
layout
=
QGridLayout
()
win
.
setLayout
(
layout
)
win
.
resize
(
600
,
500
)
combo
=
QComboBox
()
combo
.
setEditable
(
True
)
[
combo
.
addItem
(
i
)
for
i
in
'AMRK META REVG TSLA WMT CT=F GC=F ^GSPC ^FTSE ^N225 EURUSD=X ETH-USD'
.
split
()]
layout
.
addWidget
(
combo
,
0
,
0
,
1
,
1
)
info
=
QLabel
()
layout
.
addWidget
(
info
,
0
,
1
,
1
,
1
)
ax
=
fplt
.
create_plot
(
init_zoom_periods
=
100
)
win
.
axs
=
[
ax
]
# finplot requres this property
axo
=
ax
.
overlay
()
layout
.
addWidget
(
ax
.
vb
.
win
,
1
,
0
,
1
,
2
)
@
lru_cache
(
maxsize
=
15
)
def
download
(
symbol
):
return
yf
.
download
(
symbol
,
'2019-01-01'
)
@
lru_cache
(
maxsize
=
100
)
def
get_name
(
symbol
):
return
yf
.
Ticker
(
symbol
).
info
.
get
(
'shortName'
)
or
symbol
plots
=
[]
def
update
(
txt
):
df
=
download
(
txt
)
if
len
(
df
)
<
20
:
# symbol does not exist
return
info
.
setText
(
'Loading symbol name...'
)
price
=
df
[
'Open Close High Low'
.
split
()]
ma20
=
df
.
Close
.
rolling
(
20
).
mean
()
ma50
=
df
.
Close
.
rolling
(
50
).
mean
()
volume
=
df
[
'Open Close Volume'
.
split
()]
ax
.
reset
()
# remove previous plots
axo
.
reset
()
# remove previous plots
fplt
.
candlestick_ochl
(
price
)
fplt
.
plot
(
ma20
,
legend
=
'MA-20'
)
fplt
.
plot
(
ma50
,
legend
=
'MA-50'
)
fplt
.
volume_ocv
(
volume
,
ax
=
axo
)
fplt
.
refresh
()
# refresh autoscaling when all plots complete
Thread
(
target
=
lambda
:
info
.
setText
(
get_name
(
txt
))).
start
()
# slow, so use thread
combo
.
currentTextChanged
.
connect
(
update
)
update
(
combo
.
currentText
())
fplt
.
show
(
qt_exec
=
False
)
# prepares plots when they're all setup
win
.
show
()
app
.
exec
()
Back
|
FazBrowse Home
|
New Git URL