-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorderway.py
46 lines (34 loc) · 994 Bytes
/
orderway.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
from exceptions import InvalidWay
class WayEnum:
def __init__(self):
pass
BUY = 0
SELL = 1
class OrderWay:
def __init__(self, way):
if way not in (WayEnum.BUY, WayEnum.SELL):
raise InvalidWay(way)
self.way = way
def __str__(self):
if self.way == WayEnum.BUY:
return 'Buy'
if self.way == WayEnum.SELL:
return 'Sell'
raise InvalidWay()
def __cmp__(self, other):
return self.way == other.way
def __eq__(self, other):
return self.way == other.way
@staticmethod
def get_opposite_way(order_way):
if order_way.way == WayEnum.BUY:
return Sell()
if order_way.way == WayEnum.SELL:
return Buy()
raise InvalidWay(order_way.way)
class Buy(OrderWay):
def __init__(self):
OrderWay.__init__(self, WayEnum.BUY)
class Sell(OrderWay):
def __init__(self):
OrderWay.__init__(self, WayEnum.SELL)