-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.py
59 lines (43 loc) · 1.5 KB
/
event.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
# from _typeshed import Self
class Event(object):
pass
class MarketEvent(Event):
def __init__(self):
self.type = 'MARKET'
class SignalEvent(Event):
def __init__(self,symbol,datetime,signal_type,quantity):
self.type = 'SIGNAL'
self.symbol = symbol
self.datetime = datetime
self.signal_type = signal_type
self.quantity = quantity
class OrderEvent(Event):
def __init__(self,symbol,order_type,quantity,direction):
self.type = 'ORDER'
self.symbol = symbol
self.order_type = order_type
self.quantity = quantity
self.direction = direction
def print_order(self):
print("Order: Symbol=%s, Type=%s, Quantity=%s, Direction=%s") % \
(self.symbol, self.order_type, self.quantity, self.direction)
class FillEvent(Event):
def __init__(self,timeindex,symbol,exchange,quantity,direction,fill_cost, commision=True):
self.type = 'FILL'
self.timeindex = timeindex
self.symbol = symbol
self.exchange = exchange
self.quantity = quantity
self.direction = direction
self.fill_cost = fill_cost
self.commision = commision
if commision is None:
self.commision = self._calculate_commision()
else:
self.commission = commision
def _calculate_commision(self):
"""
TODO: Commission fees to be implemented
"""
# between 1 and 2%
return max(1.5, 0.015 * self.quantity)