forked from Cleanpakin/Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.py
129 lines (117 loc) · 3.55 KB
/
Graph.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import pandas as pd
import pandas_datareader as web
import mplfinance as mpf
import datetime as dt
import matplotlib.pyplot as plt
# Read csv file
crypto = []
df = pd.read_csv('Cryptocurrency Dataset.csv')
for i in df['Name']:
crypto.append(i)
# Set up chart
colors = mpf.make_marketcolors(
up='#00ff00',
down='#ff0000',
wick='in',
edge='in',
ohlc='in',
volume='in'
)
mpf_style = mpf.make_mpf_style(
base_mpf_style='nightclouds',
marketcolors=colors
)
# Make chart
def currency_chart(item,ma,v,number,currency):
start = dt.datetime(2019,1,1)
end = dt.datetime.now()
n = 0
for i in crypto:
if i == currency:
symbol = df['Symbol'][n]
else:
n+=1
data = web.DataReader(f'{symbol}-USD','yahoo',start,end)
ma_list=[]
text=''
innumber = [x for x in number]
for i in range(len(innumber)):
if innumber[i] in '0123456789':
text = text + number[i]
if innumber[i] not in '0123456789' and text != '':
ma_list.append(int(text))
text = ''
if i == len(number)-1 and number[i] in '0123456789':
ma_list.append(int(text))
if ma:
if item == 'line':
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = item,
style = mpf_style,
linecolor = '#2a60f4',
volume = v,
mav = ma_list,
returnfig = True
)
elif item == 'candle' or item == 'ohlc':
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = item,
style = mpf_style,
volume = v,
mav = ma_list
)
else:
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = 'line',
style = mpf_style,
linecolor = '#2a60f4',
fill_between = dict(y1=data['Close'].values,color = '#141c34'),
volume = v,
mav = ma_list
)
else:
if item == 'line':
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = item,
style = mpf_style,
linecolor = '#2a60f4',
volume = v
)
elif item == 'candle' or item == 'ohlc':
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = item,
style = mpf_style,
volume = v
)
else:
mpf.plot(
data,
axtitle = f'{currency} Chart',
xlabel = 'Date',
ylabel = 'Price (USD)',
type = 'line',
style = mpf_style,
linecolor = '#2a60f4',
fill_between = dict(y1=data['Close'].values,color = '#141c34'),
volume = v
)