From 788aa4acb7795387d4e309c6b4f0434ceb4fa5a7 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 27 Jun 2017 17:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=B7=E5=B7=AE=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E6=A8=A1=E5=9D=97=E7=9A=84=E4=B8=80=E9=94=AE=E5=85=A8?= =?UTF-8?q?=E5=81=9C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/app/spreadTrading/stAlgo.py | 18 +++---- vnpy/trader/app/spreadTrading/uiStWidget.py | 49 ++++++++++++++----- .../gateway/ctpGateway/CTP_connect.json | 4 +- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/vnpy/trader/app/spreadTrading/stAlgo.py b/vnpy/trader/app/spreadTrading/stAlgo.py index 3cb24c70..afd4f743 100644 --- a/vnpy/trader/app/spreadTrading/stAlgo.py +++ b/vnpy/trader/app/spreadTrading/stAlgo.py @@ -282,21 +282,21 @@ class SniperAlgo(StAlgoTemplate): #---------------------------------------------------------------------- def start(self): """启动""" + if not self.active: + self.quoteCount = 0 + self.hedgeCount = 0 + self.active = True - - self.quoteCount = 0 - self.hedgeCount = 0 - return self.active #---------------------------------------------------------------------- def stop(self): """停止""" - self.active = False - - self.hedgingTaskDict.clear() - self.cancelAllOrders() - + if self.active: + self.hedgingTaskDict.clear() + self.cancelAllOrders() + + self.active = False return self.active #---------------------------------------------------------------------- diff --git a/vnpy/trader/app/spreadTrading/uiStWidget.py b/vnpy/trader/app/spreadTrading/uiStWidget.py index 76fd714e..d2613146 100644 --- a/vnpy/trader/app/spreadTrading/uiStWidget.py +++ b/vnpy/trader/app/spreadTrading/uiStWidget.py @@ -319,16 +319,25 @@ class StActiveButton(QtWidgets.QPushButton): def buttonClicked(self): """改变运行模式""" if self.active: - algoActive = self.algoEngine.stopAlgo(self.spreadName) - - if not algoActive: - self.setStopped() + self.stop else: - algoActive = self.algoEngine.startAlgo(self.spreadName) - - if algoActive: - self.setStarted() + self.start() + #---------------------------------------------------------------------- + def stop(self): + """停止""" + algoActive = self.algoEngine.stopAlgo(self.spreadName) + if not algoActive: + self.setStopped() + + #---------------------------------------------------------------------- + def start(self): + """启动""" + algoActive = self.algoEngine.startAlgo(self.spreadName) + + if algoActive: + self.setStarted() + #---------------------------------------------------------------------- def setStarted(self): """算法启动""" @@ -350,7 +359,7 @@ class StActiveButton(QtWidgets.QPushButton): ######################################################################## class StAlgoManager(QtWidgets.QTableWidget): - """""" + """价差算法管理组件""" #---------------------------------------------------------------------- def __init__(self, stEngine, parent=None): @@ -359,6 +368,8 @@ class StAlgoManager(QtWidgets.QTableWidget): self.algoEngine = stEngine.algoEngine + self.buttonActiveDict = {} # spreadName: buttonActive + self.initUi() #---------------------------------------------------------------------- @@ -413,6 +424,14 @@ class StAlgoManager(QtWidgets.QTableWidget): self.setCellWidget(row, 9, buttonActive) buttonActive.signalActive.connect(comboMode.algoActiveChanged) + + self.buttonActiveDict[d['spreadName']] = buttonActive + + #---------------------------------------------------------------------- + def stopAll(self): + """停止所有算法""" + for button in self.buttonActiveDict.values(): + button.stop() ######################################################################## @@ -450,10 +469,6 @@ class StManager(QtWidgets.QWidget): """初始化界面""" self.setWindowTitle(u'价差交易') - # 创建按钮 - buttonInit = QtWidgets.QPushButton(u'初始化') - buttonInit.clicked.connect(self.init) - # 创建组件 tickMonitor = StTickMonitor(self.mainEngine, self.eventEngine) posMonitor = StPosMonitor(self.mainEngine, self.eventEngine) @@ -461,6 +476,13 @@ class StManager(QtWidgets.QWidget): self.algoManager = StAlgoManager(self.stEngine) algoLogMonitor = StAlgoLogMonitor(self.mainEngine, self.eventEngine) + # 创建按钮 + buttonInit = QtWidgets.QPushButton(u'初始化') + buttonInit.clicked.connect(self.init) + + buttonStopAll = QtWidgets.QPushButton(u'全部停止') + buttonStopAll.clicked.connect(self.algoManager.stopAll) + # 创建集合 groupTick = StGroup(tickMonitor, u'价差行情') groupPos = StGroup(posMonitor, u'价差持仓') @@ -472,6 +494,7 @@ class StManager(QtWidgets.QWidget): hbox = QtWidgets.QHBoxLayout() hbox.addWidget(buttonInit) hbox.addStretch() + hbox.addWidget(buttonStopAll) grid = QtWidgets.QGridLayout() grid.addLayout(hbox, 0, 0, 1, 2) diff --git a/vnpy/trader/gateway/ctpGateway/CTP_connect.json b/vnpy/trader/gateway/ctpGateway/CTP_connect.json index e4bfa6b8..1b4d5a42 100644 --- a/vnpy/trader/gateway/ctpGateway/CTP_connect.json +++ b/vnpy/trader/gateway/ctpGateway/CTP_connect.json @@ -2,6 +2,6 @@ "brokerID": "9999", "mdAddress": "tcp://180.168.146.187:10011", "tdAddress": "tcp://180.168.146.187:10001", - "userID": "simnow申请", - "password": "simnow申请" + "userID": "000300", + "password": "19890624" } \ No newline at end of file