-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicBTCUSDgraph.py
71 lines (50 loc) · 1.79 KB
/
BasicBTCUSDgraph.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
## I used this to see if my chart is even accurate
import requests
import time
import datetime
from inputimeout import inputimeout, TimeoutOccurred
from datetime import datetime
from matplotlib import pyplot
from matplotlib.animation import FuncAnimation
from matplotlib.pyplot import xlim
bitcoinList = []
ethereumList = []
count = 0
count2 = 0
# from the visualizer
x_data, y_data = [], []
figure = pyplot.figure()
line, = pyplot.plot_date(x_data, y_data, '-')
def update(frame):
x_data.append(datetime.now())
try:
user_input = inputimeout(prompt='q?', timeout=1)
if user_input == 'q':
print("the length of the bitcoin list is " + str(len(bitcoinList)))
print("the first value in the list is " + str(bitcoinList[0]))
print("the last value in the list is " + str(bitcoinList[len(bitcoinList)-1]))
quit()
except TimeoutOccurred:
pass
url = "http://api.coincap.io/v2/assets/bitcoin/"
payload = {}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
bitcoinPrice = response.json()['data']['priceUsd']
bitcoinList.append(float(bitcoinPrice))
while len(bitcoinList) > 60:
bitcoinList.pop(0)
currentPrice = bitcoinList[len(bitcoinList)-1]
print(currentPrice)
y_data.append(currentPrice)
line.set_data(x_data, y_data)
figure.gca().relim()
figure.gca().autoscale_view()
return line,
while (True and count < 500):
animation = FuncAnimation(figure, update, interval=1000)
if count2 == 0:
pyplot.show()
count2 += 1
count +=1
######## from visualizer