-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandaplot.py
More file actions
76 lines (74 loc) · 2.36 KB
/
pandaplot.py
File metadata and controls
76 lines (74 loc) · 2.36 KB
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
import pandas as pd
import matplotlib.pyplot as plt
import time
import datetime
import requests
t = time.time()
def plot_chart_1d(symbol):
t = time.time()
plt.style.use('dark_background')
url_l = 'https://api.iextrading.com/1.0/stock/'
url = url_l+ symbol + '/chart/1d'
df = pd.read_json(url)
df.set_index('minute', inplace = True)
df.index = pd.to_datetime(df.index, format = '%H:%M')
df['average'].plot(grid = True)
plt.ylabel('Price/USD')
xlabell = 'Last Refreshed: ' + str(datetime.datetime.now())
plt.xlabel(xlabell)
plt.title('Price (1D) Company Symbol: '+symbol.upper())
plt.savefig('display.png')
t1 = time.time()
print(t1-t)
def plot_chart_1m(symbol):
t = time.time()
plt.style.use('dark_background')
url_l = 'https://api.iextrading.com/1.0/stock/'
url = url_l+ symbol + '/chart/1m'
df = pd.read_json(url)
df.set_index('date', inplace = True)
df.index = pd.to_datetime(df.index, format = '%Y-%m-%d')
df['close'].plot(grid = True)
plt.ylabel('Price/USD')
xlabell = 'Last Refreshed: ' + str(datetime.datetime.now())
plt.xlabel(xlabell)
plt.title('Price (1M) Company Symbol: '+symbol.upper())
plt.savefig('display.png')
t1 = time.time()
print(t1-t)
def plot_chart_1y(symbol):
t = time.time()
plt.style.use('dark_background')
url_l = 'https://api.iextrading.com/1.0/stock/'
url = url_l+ symbol + '/chart/1y'
df = pd.read_json(url)
df.set_index('date', inplace = True)
df.index = pd.to_datetime(df.index, format = '%Y-%m-%d')
df['close'].plot(grid = True)
plt.ylabel('Price/USD')
xlabell = 'Last Refreshed: ' + str(datetime.datetime.now())
plt.xlabel(xlabell)
plt.title('Price (1Y) Company Symbol: '+symbol.upper())
plt.savefig('display.png')
t1 = time.time()
print(t1-t)
def plot_chart_dynamic(symbol):
t = time.time()
plt.style.use('dark_background')
url_l = 'https://api.iextrading.com/1.0/stock/'
url = url_l+ symbol + '/chart/dynamic'
r = requests.get(url)
r = r.json()
df = pd.DataFrame(r['data'])
df.set_index('minute', inplace = True)
df.index = pd.to_datetime(df.index, errors = 'ignore', format = '%H:%M') #format = '%Y-%m-%d')
df['open'].plot(grid = True)
plt.ylabel('Price/USD')
xlabell = 'Last Refreshed: ' + str(datetime.datetime.now())
plt.xlabel(xlabell)
plt.title('Price (Dynamic) Company Symbol: '+symbol.upper())
plt.savefig('display.png')
t1 = time.time()
print(t1-t)
#plot_chart_1d('jd')
#plot_chart_dynamic('amzn')