-
Notifications
You must be signed in to change notification settings - Fork 1
/
ITradingBrain.py
45 lines (37 loc) · 1.36 KB
/
ITradingBrain.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
__author__ = 'shgli'
from ITradingComponent import ITradingComponent
from EventNode import EventNode
import EventType
class ITradingBrain(ITradingComponent, EventNode):
def __init__(self, name, type, tradingContext):
super(ITradingBrain, self).__init__(name, tradingContext)
EventNode.__init__(self, name, type)
self.tradingContext.eventFlow.addNode(self)
self.__timer = []
self.__marketData = []
def subscribe(self,symbol):
instrument = self.tradingContext.instrumentManager.getFuture(symbol)
if instrument is None:
return None
return self.tradingContext.feedSource.subscribe(instrument)
def onRaised(self,source):
if EventType.FeedEvent == source.evtType:
self.__marketData.append(source)
elif EventType.TimerEvent == source.evtType:
self.__timer.append(source)
def onMarketData(self,data):
pass
def onTimer(self,timer):
pass
def doProcess(self, processId):
hasEvent = False
if 0 != len(self.__marketData):
self.onMarketData(self.__marketData)
self.__marketData = []
hasEvent = True
if 0 != len(self.__timer):
for timer in self.__timer:
self.onTimer(timer)
self.__timer = []
hasEvent = True
return hasEvent