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