-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_v2.py
85 lines (61 loc) · 1.66 KB
/
GUI_v2.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
import cv2
import numpy as np
import requests
from time import sleep
URL = "https://api.wazirx.com/api/v2/tickers"
PAIR = 'btcinr'
# Waiting time in seconds
WAITING_TIME = 60
# Window size in pixels
WINDOW_SIZE = (300, 500, 3)
def get_data():
response = requests.get(URL)
_ = response.json()
buy = float((_[PAIR]['buy']))
sell = float((_[PAIR]['sell']))
avg = float((buy+sell)/2)
return [buy, sell, avg]
def change(old):
new = get_data()[2]
# print('New', new)
delta = (new-old)
if delta >= 0:
col = (0, 150, 0)
# Green
else:
col = (0, 0, 150)
# Red
return [delta, col]
def add_text(text, location, color=(255, 255, 255), scale=1):
cv2.putText(img,
org=location,
text=text,
fontFace=0,
fontScale=scale,
thickness=2,
lineType=2,
color=color)
while True:
data = get_data()
old_avg = ((data[0] + data[1])/2)
delta_attr = change(old_avg)
deltacolor = delta_attr[1]
deltavalue = delta_attr[0]
# print('Old', old_avg)
# print('Chg', deltavalue, '\n')
img = np.zeros(WINDOW_SIZE, dtype=np.uint8)
add_text(PAIR,
(10, 100),
scale=3,
color=(175, 90, 55))
add_text(f'Buying Price = {data[0]}',
(10, 150))
add_text(f'Selling Price = {data[1]}',
(10, 200))
add_text(f'Change Since Last = {deltavalue}',
(10, 250),
color=deltacolor)
cv2.imshow(PAIR.upper() + 'Price Ticker', img)
cv2.waitKey(1)
sleep(WAITING_TIME)
cv2.destroyAllWindows()