-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.py
67 lines (54 loc) · 2.05 KB
/
objects.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
from enum import Enum
from calls import get_last_price
# the alert class, holds the price and whether to check for it being below or above
class Alert(object):
def __init__(self, market, value, g_l):
self.market = market
self.value = value
self.g_l = g_l
# the alert event class, this is sent back when an alert is triggered
class AlertEvent(object):
def __init__(self, alert, info):
self.alert = alert
self.info = info
class Exchange(Enum):
Bittrex = 1
Binance = 2
class Market(Enum):
BTC = 1
ETH = 2
USDT = 3
BNB = 4
# the coin class, this is used to hold info about a coin including list of alerts
class Coin(object):
def __init__(self, name, exchange, market, market_price, usd_price):
self.name = name
self.exchange = exchange
self.market = market
##used for btc-XXX, ltc-XXX etc
self.market_price = market_price
self.usd_price = usd_price
self.alerts = []
self.displayed = False
def check_alerts(self):
alert_events = []
for a in self.alerts:
old_price = float(a.value)
new_price = get_last_price[self.exchange](a.market, self.name)
if a.g_l:
if new_price > old_price:
alert_events.append(AlertEvent(a, "price is now " + str(
new_price) + "" + self.market + "(greater than the alert price, set at " + str(
old_price) + ")"))
self.remove_alert(a)
else:
if new_price < old_price:
alert_events.append(AlertEvent(a, "price is now " + str(
new_price) + "" + self.market + "(less than the alert price, set at " + str(old_price) + ")"))
self.remove_alert(a)
return alert_events
def add_alert(self, alert):
if alert not in self.alerts:
self.alerts.append(alert)
def remove_alert(self, alert):
self.alerts = [x for x in self.alerts if x != alert]