From 387332aee637ba3a1ec4c25fb4c09cc4f6aa8cb3 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 22 Feb 2018 16:18:05 +0800 Subject: [PATCH] =?UTF-8?q?[Add]DataEngine=E6=96=B0=E5=A2=9E=E8=A1=8C?= =?UTF-8?q?=E6=83=85=E7=BC=93=E5=AD=98=E5=92=8C=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/vtEngine.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 86168da3..cfd1c5f1 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -264,6 +264,11 @@ class MainEngine(object): } self.dbInsert(LOG_DB_NAME, self.todayDate, d) + #---------------------------------------------------------------------- + def getTick(self, vtSymbol): + """查询行情""" + return self.dataEngine.getTick(vtSymbol) + #---------------------------------------------------------------------- def getContract(self, vtSymbol): """查询合约""" @@ -395,6 +400,7 @@ class DataEngine(object): self.eventEngine = eventEngine # 保存数据的字典和列表 + self.tickDict = {} self.contractDict = {} self.orderDict = {} self.workingOrderDict = {} # 可撤销委托 @@ -417,6 +423,7 @@ class DataEngine(object): #---------------------------------------------------------------------- def registerEvent(self): """注册事件监听""" + self.eventEngine.register(EVENT_TICK, self.processTickEvent) self.eventEngine.register(EVENT_CONTRACT, self.processContractEvent) self.eventEngine.register(EVENT_ORDER, self.processOrderEvent) self.eventEngine.register(EVENT_TRADE, self.processTradeEvent) @@ -424,6 +431,12 @@ class DataEngine(object): self.eventEngine.register(EVENT_ACCOUNT, self.processAccountEvent) self.eventEngine.register(EVENT_LOG, self.processLogEvent) self.eventEngine.register(EVENT_ERROR, self.processErrorEvent) + + #---------------------------------------------------------------------- + def processTickEvent(self, event): + """处理成交事件""" + tick = event.dict_['data'] + self.tickDict[tick.vtSymbol] = tick #---------------------------------------------------------------------- def processContractEvent(self, event): @@ -489,6 +502,14 @@ class DataEngine(object): """处理错误事件""" error = event.dict_['data'] self.errorList.append(error) + + #---------------------------------------------------------------------- + def getTick(self, vtSymbol): + """查询行情对象""" + try: + return self.tickDict[vtSymbol] + except KeyError: + return None #---------------------------------------------------------------------- def getContract(self, vtSymbol):