将mainEngine的gateway获取独立为一个函数
This commit is contained in:
parent
260c58643f
commit
b3911e4280
@ -62,30 +62,37 @@ class MainEngine(object):
|
|||||||
print e
|
print e
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def addGateway(self, gateway, gatewayName=None):
|
def addGateway(self, gatewayClass, gatewayName=None):
|
||||||
"""创建接口"""
|
"""创建接口"""
|
||||||
self.gatewayDict[gatewayName] = gateway(self.eventEngine, gatewayName)
|
self.gatewayDict[gatewayName] = gatewayClass(self.eventEngine, gatewayName)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def getGateway(self, gatewayName):
|
||||||
|
"""获取接口"""
|
||||||
|
if gatewayName in self.gatewayDict:
|
||||||
|
return self.gatewayDict[gatewayName]
|
||||||
|
else:
|
||||||
|
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||||
|
return None
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def connect(self, gatewayName):
|
def connect(self, gatewayName):
|
||||||
"""连接特定名称的接口"""
|
"""连接特定名称的接口"""
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
|
if gateway:
|
||||||
gateway.connect()
|
gateway.connect()
|
||||||
|
|
||||||
# 接口连接后自动执行数据库连接的任务
|
# 接口连接后自动执行数据库连接的任务
|
||||||
self.dbConnect()
|
self.dbConnect()
|
||||||
else:
|
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def subscribe(self, subscribeReq, gatewayName):
|
def subscribe(self, subscribeReq, gatewayName):
|
||||||
"""订阅特定接口的行情"""
|
"""订阅特定接口的行情"""
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
|
if gateway:
|
||||||
gateway.subscribe(subscribeReq)
|
gateway.subscribe(subscribeReq)
|
||||||
else:
|
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def sendOrder(self, orderReq, gatewayName):
|
def sendOrder(self, orderReq, gatewayName):
|
||||||
@ -94,39 +101,36 @@ class MainEngine(object):
|
|||||||
if not self.rmEngine.checkRisk(orderReq):
|
if not self.rmEngine.checkRisk(orderReq):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
|
if gateway:
|
||||||
return gateway.sendOrder(orderReq)
|
return gateway.sendOrder(orderReq)
|
||||||
else:
|
else:
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
return ''
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def cancelOrder(self, cancelOrderReq, gatewayName):
|
def cancelOrder(self, cancelOrderReq, gatewayName):
|
||||||
"""对特定接口撤单"""
|
"""对特定接口撤单"""
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
gateway.cancelOrder(cancelOrderReq)
|
|
||||||
else:
|
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
|
||||||
|
|
||||||
|
if gateway:
|
||||||
|
gateway.cancelOrder(cancelOrderReq)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def qryAccount(self, gatewayName):
|
def qryAccount(self, gatewayName):
|
||||||
"""查询特定接口的账户"""
|
"""查询特定接口的账户"""
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
|
if gateway:
|
||||||
gateway.qryAccount()
|
gateway.qryAccount()
|
||||||
else:
|
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def qryPosition(self, gatewayName):
|
def qryPosition(self, gatewayName):
|
||||||
"""查询特定接口的持仓"""
|
"""查询特定接口的持仓"""
|
||||||
if gatewayName in self.gatewayDict:
|
gateway = self.getGateway(gatewayName)
|
||||||
gateway = self.gatewayDict[gatewayName]
|
|
||||||
|
if gateway:
|
||||||
gateway.qryPosition()
|
gateway.qryPosition()
|
||||||
else:
|
|
||||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def exit(self):
|
def exit(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user