From 3cbf54cffa2fe3a6a521198f24ad281dd21a2d6d Mon Sep 17 00:00:00 2001 From: lamter Date: Wed, 26 Apr 2017 23:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=20-=20add=20:=20=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=9D=A5=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=E5=8F=AF=E5=8A=A0=E8=BD=BD=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/VT_setting.json | 7 ++-- vn.trader/uiMainWindow.py | 74 +++++++++++++++++++++++++-------------- vn.trader/vtClient.py | 3 ++ vn.trader/vtEngine.py | 18 ++++++++-- vn.trader/vtServer.py | 4 +-- 5 files changed, 72 insertions(+), 34 deletions(-) diff --git a/vn.trader/VT_setting.json b/vn.trader/VT_setting.json index 9d90a0a2..5e455ac1 100644 --- a/vn.trader/VT_setting.json +++ b/vn.trader/VT_setting.json @@ -5,12 +5,13 @@ "mongoHost": "localhost", "mongoPort": 27017, "mongoLogging": true, - "automongodb": true, + "automongodb": false, "darkStyle": true, "language": "chinese", - "CTP_connect": null, - "autoctp": true, + + "CTP_connect": "./gateway/ctpGateway/CTP_connect.json", + "autoctp": false, "autoshutdown": true diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index c9feffca..2180c4c4 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -2,7 +2,7 @@ import psutil -from gateway import GATEWAY_DICT +# from gateway import GATEWAY_DICT from uiBasicWidget import * from ctaStrategy.uiCtaWidget import CtaEngineManager from dataRecorder.uiDrWidget import DrEngineManager @@ -69,34 +69,54 @@ class MainWindow(QtGui.QMainWindow): # 设计为只显示存在的接口 sysMenu = menubar.addMenu(vtText.SYSTEM) - for gatewayModule in GATEWAY_DICT.values(): - if gatewayModule.gatewayType == GATEWAYTYPE_FUTURES: - self.addConnectAction(sysMenu, gatewayModule.gatewayName, - gatewayModule.gatewayDisplayName) - - sysMenu.addSeparator() - for gatewayModule in GATEWAY_DICT.values(): - if gatewayModule.gatewayType == GATEWAYTYPE_EQUITY: - self.addConnectAction(sysMenu, gatewayModule.gatewayName, - gatewayModule.gatewayDisplayName) + # 鉴于前后端分离,此处不应当直接检查本地的gateway接口可用情况,而是应当向服务端查询 + GATEWAY_TYPES = [ + GATEWAYTYPE_FUTURES, + GATEWAYTYPE_EQUITY, + GATEWAYTYPE_INTERNATIONAL, + GATEWAYTYPE_BTC, + GATEWAYTYPE_DATA, - sysMenu.addSeparator() - for gatewayModule in GATEWAY_DICT.values(): - if gatewayModule.gatewayType == GATEWAYTYPE_INTERNATIONAL: - self.addConnectAction(sysMenu, gatewayModule.gatewayName, - gatewayModule.gatewayDisplayName) - - sysMenu.addSeparator() - for gatewayModule in GATEWAY_DICT.values(): - if gatewayModule.gatewayType == GATEWAYTYPE_BTC: - self.addConnectAction(sysMenu, gatewayModule.gatewayName, - gatewayModule.gatewayDisplayName) + ] - sysMenu.addSeparator() - for gatewayModule in GATEWAY_DICT.values(): - if gatewayModule.gatewayType == GATEWAYTYPE_DATA: - self.addConnectAction(sysMenu, gatewayModule.gatewayName, - gatewayModule.gatewayDisplayName) + # 获取可链接的交易接口 + gateways = self.mainEngine.getGateway4sysMenu() + + # 模拟一个GateWay 实例 + for g in gateways: + sysMenu.addSeparator() + if g['gatewayType'] in GATEWAY_TYPES: + self.addConnectAction(sysMenu, g['gatewayName'], + g['gatewayDisplayName']) + + # for gatewayModule in GATEWAY_DICT.values(): + # if gatewayModule.gatewayType == GATEWAYTYPE_FUTURES: + # self.addConnectAction(sysMenu, gatewayModule.gatewayName, + # gatewayModule.gatewayDisplayName) + # + # sysMenu.addSeparator() + # for gatewayModule in GATEWAY_DICT.values(): + # if gatewayModule.gatewayType == GATEWAYTYPE_EQUITY: + # self.addConnectAction(sysMenu, gatewayModule.gatewayName, + # gatewayModule.gatewayDisplayName) + # + # sysMenu.addSeparator() + # for gatewayModule in GATEWAY_DICT.values(): + # if gatewayModule.gatewayType == GATEWAYTYPE_INTERNATIONAL: + # self.addConnectAction(sysMenu, gatewayModule.gatewayName, + # gatewayModule.gatewayDisplayName) + # + # sysMenu.addSeparator() + # for gatewayModule in GATEWAY_DICT.values(): + # if gatewayModule.gatewayType == GATEWAYTYPE_BTC: + # self.addConnectAction(sysMenu, gatewayModule.gatewayName, + # gatewayModule.gatewayDisplayName) + # + # sysMenu.addSeparator() + # for gatewayModule in GATEWAY_DICT.values(): + # if gatewayModule.gatewayType == GATEWAYTYPE_DATA: + # self.addConnectAction(sysMenu, gatewayModule.gatewayName, + # gatewayModule.gatewayDisplayName) sysMenu.addSeparator() sysMenu.addAction(self.createAction(vtText.CONNECT_DATABASE, self.mainEngine.dbConnect)) diff --git a/vn.trader/vtClient.py b/vn.trader/vtClient.py index d5c38cfa..72b6ebeb 100644 --- a/vn.trader/vtClient.py +++ b/vn.trader/vtClient.py @@ -152,6 +152,9 @@ class ClientEngine(object): """查询所有的接口名称""" return self.client.getAllGatewayNames() + # ---------------------------------------------------------------------- + def getGateway4sysMenu(self): + return self.client.getGateway4sysMenu() #---------------------------------------------------------------------- def main(): diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index ec9c796a..aaba28e8 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -246,8 +246,22 @@ class MainEngine(object): def getAllGatewayNames(self): """查询引擎中所有可用接口的名称""" return self.gatewayDict.keys() - - + + # ---------------------------------------------------------------------- + def getGateway4sysMenu(self): + """ + + :return: + """ + + toDict = lambda g: { + 'gatewayType': g.gatewayType, + 'gatewayName': g.gatewayName, + 'gatewayDisplayName': g.gatewayDisplayName, + } + return [ + toDict(g) for g in GATEWAY_DICT.values() if hasattr(g, 'gatewayType') + ] ######################################################################## class DataEngine(object): diff --git a/vn.trader/vtServer.py b/vn.trader/vtServer.py index 4742f193..e85c04f4 100644 --- a/vn.trader/vtServer.py +++ b/vn.trader/vtServer.py @@ -43,7 +43,8 @@ class VtServer(RpcServer): self.register(self.engine.getOrder) self.register(self.engine.getAllWorkingOrders) self.register(self.engine.getAllGatewayNames) - + self.register(self.engine.getGateway4sysMenu) + # 注册事件引擎发送的事件处理监听 self.engine.eventEngine.registerGeneralHandler(self.eventHandler) @@ -87,7 +88,6 @@ def runServer(): # 自动建立MongoDB数据库 printLog(u'MongoDB connect... ') server.engine.dbConnect() - printLog(u'MongoDB OK... ') if VT_setting.get('autoctp'): # 自动建立CTP链接