[Add]DataEngine新增行情缓存和查询
This commit is contained in:
parent
622ebd70d2
commit
387332aee6
@ -264,6 +264,11 @@ class MainEngine(object):
|
|||||||
}
|
}
|
||||||
self.dbInsert(LOG_DB_NAME, self.todayDate, d)
|
self.dbInsert(LOG_DB_NAME, self.todayDate, d)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def getTick(self, vtSymbol):
|
||||||
|
"""查询行情"""
|
||||||
|
return self.dataEngine.getTick(vtSymbol)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def getContract(self, vtSymbol):
|
def getContract(self, vtSymbol):
|
||||||
"""查询合约"""
|
"""查询合约"""
|
||||||
@ -395,6 +400,7 @@ class DataEngine(object):
|
|||||||
self.eventEngine = eventEngine
|
self.eventEngine = eventEngine
|
||||||
|
|
||||||
# 保存数据的字典和列表
|
# 保存数据的字典和列表
|
||||||
|
self.tickDict = {}
|
||||||
self.contractDict = {}
|
self.contractDict = {}
|
||||||
self.orderDict = {}
|
self.orderDict = {}
|
||||||
self.workingOrderDict = {} # 可撤销委托
|
self.workingOrderDict = {} # 可撤销委托
|
||||||
@ -417,6 +423,7 @@ class DataEngine(object):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def registerEvent(self):
|
def registerEvent(self):
|
||||||
"""注册事件监听"""
|
"""注册事件监听"""
|
||||||
|
self.eventEngine.register(EVENT_TICK, self.processTickEvent)
|
||||||
self.eventEngine.register(EVENT_CONTRACT, self.processContractEvent)
|
self.eventEngine.register(EVENT_CONTRACT, self.processContractEvent)
|
||||||
self.eventEngine.register(EVENT_ORDER, self.processOrderEvent)
|
self.eventEngine.register(EVENT_ORDER, self.processOrderEvent)
|
||||||
self.eventEngine.register(EVENT_TRADE, self.processTradeEvent)
|
self.eventEngine.register(EVENT_TRADE, self.processTradeEvent)
|
||||||
@ -425,6 +432,12 @@ class DataEngine(object):
|
|||||||
self.eventEngine.register(EVENT_LOG, self.processLogEvent)
|
self.eventEngine.register(EVENT_LOG, self.processLogEvent)
|
||||||
self.eventEngine.register(EVENT_ERROR, self.processErrorEvent)
|
self.eventEngine.register(EVENT_ERROR, self.processErrorEvent)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def processTickEvent(self, event):
|
||||||
|
"""处理成交事件"""
|
||||||
|
tick = event.dict_['data']
|
||||||
|
self.tickDict[tick.vtSymbol] = tick
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def processContractEvent(self, event):
|
def processContractEvent(self, event):
|
||||||
"""处理合约事件"""
|
"""处理合约事件"""
|
||||||
@ -490,6 +503,14 @@ class DataEngine(object):
|
|||||||
error = event.dict_['data']
|
error = event.dict_['data']
|
||||||
self.errorList.append(error)
|
self.errorList.append(error)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def getTick(self, vtSymbol):
|
||||||
|
"""查询行情对象"""
|
||||||
|
try:
|
||||||
|
return self.tickDict[vtSymbol]
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def getContract(self, vtSymbol):
|
def getContract(self, vtSymbol):
|
||||||
"""查询合约对象"""
|
"""查询合约对象"""
|
||||||
|
Loading…
Reference in New Issue
Block a user