增加价差交易模块的一键全停功能

This commit is contained in:
vn.py 2017-06-27 17:14:35 +08:00
parent b3cdb0e2c0
commit 788aa4acb7
3 changed files with 47 additions and 24 deletions

View File

@ -282,21 +282,21 @@ class SniperAlgo(StAlgoTemplate):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def start(self): def start(self):
"""启动""" """启动"""
if not self.active:
self.quoteCount = 0
self.hedgeCount = 0
self.active = True self.active = True
self.quoteCount = 0
self.hedgeCount = 0
return self.active return self.active
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def stop(self): def stop(self):
"""停止""" """停止"""
self.active = False if self.active:
self.hedgingTaskDict.clear()
self.hedgingTaskDict.clear() self.cancelAllOrders()
self.cancelAllOrders()
self.active = False
return self.active return self.active
#---------------------------------------------------------------------- #----------------------------------------------------------------------

View File

@ -319,16 +319,25 @@ class StActiveButton(QtWidgets.QPushButton):
def buttonClicked(self): def buttonClicked(self):
"""改变运行模式""" """改变运行模式"""
if self.active: if self.active:
algoActive = self.algoEngine.stopAlgo(self.spreadName) self.stop
if not algoActive:
self.setStopped()
else: else:
algoActive = self.algoEngine.startAlgo(self.spreadName) self.start()
if algoActive:
self.setStarted()
#----------------------------------------------------------------------
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): def setStarted(self):
"""算法启动""" """算法启动"""
@ -350,7 +359,7 @@ class StActiveButton(QtWidgets.QPushButton):
######################################################################## ########################################################################
class StAlgoManager(QtWidgets.QTableWidget): class StAlgoManager(QtWidgets.QTableWidget):
"""""" """价差算法管理组件"""
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def __init__(self, stEngine, parent=None): def __init__(self, stEngine, parent=None):
@ -359,6 +368,8 @@ class StAlgoManager(QtWidgets.QTableWidget):
self.algoEngine = stEngine.algoEngine self.algoEngine = stEngine.algoEngine
self.buttonActiveDict = {} # spreadName: buttonActive
self.initUi() self.initUi()
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -413,6 +424,14 @@ class StAlgoManager(QtWidgets.QTableWidget):
self.setCellWidget(row, 9, buttonActive) self.setCellWidget(row, 9, buttonActive)
buttonActive.signalActive.connect(comboMode.algoActiveChanged) 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'价差交易') self.setWindowTitle(u'价差交易')
# 创建按钮
buttonInit = QtWidgets.QPushButton(u'初始化')
buttonInit.clicked.connect(self.init)
# 创建组件 # 创建组件
tickMonitor = StTickMonitor(self.mainEngine, self.eventEngine) tickMonitor = StTickMonitor(self.mainEngine, self.eventEngine)
posMonitor = StPosMonitor(self.mainEngine, self.eventEngine) posMonitor = StPosMonitor(self.mainEngine, self.eventEngine)
@ -461,6 +476,13 @@ class StManager(QtWidgets.QWidget):
self.algoManager = StAlgoManager(self.stEngine) self.algoManager = StAlgoManager(self.stEngine)
algoLogMonitor = StAlgoLogMonitor(self.mainEngine, self.eventEngine) 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'价差行情') groupTick = StGroup(tickMonitor, u'价差行情')
groupPos = StGroup(posMonitor, u'价差持仓') groupPos = StGroup(posMonitor, u'价差持仓')
@ -472,6 +494,7 @@ class StManager(QtWidgets.QWidget):
hbox = QtWidgets.QHBoxLayout() hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(buttonInit) hbox.addWidget(buttonInit)
hbox.addStretch() hbox.addStretch()
hbox.addWidget(buttonStopAll)
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
grid.addLayout(hbox, 0, 0, 1, 2) grid.addLayout(hbox, 0, 0, 1, 2)

View File

@ -2,6 +2,6 @@
"brokerID": "9999", "brokerID": "9999",
"mdAddress": "tcp://180.168.146.187:10011", "mdAddress": "tcp://180.168.146.187:10011",
"tdAddress": "tcp://180.168.146.187:10001", "tdAddress": "tcp://180.168.146.187:10001",
"userID": "simnow申请", "userID": "000300",
"password": "simnow申请" "password": "19890624"
} }