sync 1.7
This commit is contained in:
parent
1fe1ed59ad
commit
a658c5bbbf
@ -9,11 +9,11 @@ import os
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from vnpy.trader.app.ctaStrategy.language import text
|
from vnpy.trader.app.ctaStrategy.language import text
|
||||||
from vnpy.trader.uiBasicWidget import QtGui, QtCore
|
from vnpy.trader.uiBasicWidget import QtWidgets, QtGui, QtCore, BasicCell
|
||||||
from vnpy.trader.vtEvent import *
|
from vnpy.trader.vtEvent import *
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class CtaValueMonitor(QtGui.QTableWidget):
|
class CtaValueMonitor(QtWidgets.QTableWidget):
|
||||||
"""参数监控"""
|
"""参数监控"""
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -48,7 +48,7 @@ class CtaValueMonitor(QtGui.QTableWidget):
|
|||||||
# 新增数据
|
# 新增数据
|
||||||
col = 0
|
col = 0
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
cell = QtGui.QTableWidgetItem(unicode(v))
|
cell = QtWidgets.QTableWidgetItem(unicode(v))
|
||||||
self.keyCellDict[k] = cell
|
self.keyCellDict[k] = cell
|
||||||
self.setItem(0, col, cell)
|
self.setItem(0, col, cell)
|
||||||
col += 1
|
col += 1
|
||||||
@ -67,9 +67,9 @@ class CtaValueMonitor(QtGui.QTableWidget):
|
|||||||
self.resizeRowsToContents()
|
self.resizeRowsToContents()
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class CtaStrategyManager(QtGui.QGroupBox):
|
class CtaStrategyManager(QtWidgets.QGroupBox):
|
||||||
"""策略管理组件"""
|
"""策略管理组件"""
|
||||||
signal = QtCore.pyqtSignal(type(Event()))
|
signal = QtCore.Signal(type(Event()))
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def __init__(self, ctaEngine, eventEngine, name, parent=None):
|
def __init__(self, ctaEngine, eventEngine, name, parent=None):
|
||||||
@ -92,20 +92,20 @@ class CtaStrategyManager(QtGui.QGroupBox):
|
|||||||
self.paramMonitor = CtaValueMonitor(self) # 参数监控
|
self.paramMonitor = CtaValueMonitor(self) # 参数监控
|
||||||
self.varMonitor = CtaValueMonitor(self) # 变量监控
|
self.varMonitor = CtaValueMonitor(self) # 变量监控
|
||||||
|
|
||||||
height = 65
|
height = 80
|
||||||
self.paramMonitor.setFixedHeight(height)
|
self.paramMonitor.setFixedHeight(height)
|
||||||
self.varMonitor.setFixedHeight(height)
|
self.varMonitor.setFixedHeight(height)
|
||||||
|
|
||||||
buttonInit = QtGui.QPushButton(text.INIT)
|
buttonInit = QtWidgets.QPushButton(text.INIT)
|
||||||
buttonStart = QtGui.QPushButton(text.START)
|
buttonStart = QtWidgets.QPushButton(text.START)
|
||||||
buttonStop = QtGui.QPushButton(text.STOP)
|
buttonStop = QtWidgets.QPushButton(text.STOP)
|
||||||
buttonInitForce = QtGui.QPushButton(u'强制初始化')
|
buttonInitForce = QtWidgets.QPushButton(text.FORCEINIT)
|
||||||
buttonInit.clicked.connect(self.init)
|
buttonInit.clicked.connect(self.init)
|
||||||
buttonStart.clicked.connect(self.start)
|
buttonStart.clicked.connect(self.start)
|
||||||
buttonStop.clicked.connect(self.stop)
|
buttonStop.clicked.connect(self.stop)
|
||||||
buttonInitForce.clicked.connect(self.initForce)
|
buttonInitForce.clicked.connect(self.initForce)
|
||||||
|
|
||||||
hbox1 = QtGui.QHBoxLayout()
|
hbox1 = QtWidgets.QHBoxLayout()
|
||||||
hbox1.addWidget(buttonInit)
|
hbox1.addWidget(buttonInit)
|
||||||
hbox1.addWidget(buttonStart)
|
hbox1.addWidget(buttonStart)
|
||||||
hbox1.addWidget(buttonStop)
|
hbox1.addWidget(buttonStop)
|
||||||
@ -113,13 +113,13 @@ class CtaStrategyManager(QtGui.QGroupBox):
|
|||||||
|
|
||||||
hbox1.addStretch()
|
hbox1.addStretch()
|
||||||
|
|
||||||
hbox2 = QtGui.QHBoxLayout()
|
hbox2 = QtWidgets.QHBoxLayout()
|
||||||
hbox2.addWidget(self.paramMonitor)
|
hbox2.addWidget(self.paramMonitor)
|
||||||
|
|
||||||
hbox3 = QtGui.QHBoxLayout()
|
hbox3 = QtWidgets.QHBoxLayout()
|
||||||
hbox3.addWidget(self.varMonitor)
|
hbox3.addWidget(self.varMonitor)
|
||||||
|
|
||||||
vbox = QtGui.QVBoxLayout()
|
vbox = QtWidgets.QVBoxLayout()
|
||||||
vbox.addLayout(hbox1)
|
vbox.addLayout(hbox1)
|
||||||
vbox.addLayout(hbox2)
|
vbox.addLayout(hbox2)
|
||||||
vbox.addLayout(hbox3)
|
vbox.addLayout(hbox3)
|
||||||
@ -171,9 +171,9 @@ class CtaStrategyManager(QtGui.QGroupBox):
|
|||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class CtaEngineManager(QtGui.QWidget):
|
class CtaEngineManager(QtWidgets.QWidget):
|
||||||
"""CTA引擎管理组件"""
|
"""CTA引擎管理组件"""
|
||||||
signal = QtCore.pyqtSignal(type(Event()))
|
signal = QtCore.Signal(type(Event()))
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def __init__(self, ctaEngine, eventEngine, parent=None):
|
def __init__(self, ctaEngine, eventEngine, parent=None):
|
||||||
@ -194,16 +194,14 @@ class CtaEngineManager(QtGui.QWidget):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def initUi(self):
|
def initUi(self):
|
||||||
"""初始化界面"""
|
"""初始化界面"""
|
||||||
path = os.getcwd().rsplit('\\')[-1]
|
self.setWindowTitle(text.CTA_STRATEGY)
|
||||||
|
|
||||||
self.setWindowTitle(u'{0} CTA策略'.format(path))
|
|
||||||
|
|
||||||
# 按钮
|
# 按钮
|
||||||
loadButton = QtGui.QPushButton(text.LOAD_STRATEGY)
|
loadButton = QtWidgets.QPushButton(text.LOAD_STRATEGY)
|
||||||
initAllButton = QtGui.QPushButton(text.INIT_ALL)
|
initAllButton = QtWidgets.QPushButton(text.INIT_ALL)
|
||||||
startAllButton = QtGui.QPushButton(text.START_ALL)
|
startAllButton = QtWidgets.QPushButton(text.START_ALL)
|
||||||
stopAllButton = QtGui.QPushButton(text.STOP_ALL)
|
stopAllButton = QtWidgets.QPushButton(text.STOP_ALL)
|
||||||
savePositionButton = QtGui.QPushButton(text.SAVE_POSITION_DATA)
|
savePositionButton = QtWidgets.QPushButton(text.SAVE_POSITION_DATA)
|
||||||
|
|
||||||
loadButton.clicked.connect(self.load)
|
loadButton.clicked.connect(self.load)
|
||||||
initAllButton.clicked.connect(self.initAll)
|
initAllButton.clicked.connect(self.initAll)
|
||||||
@ -212,16 +210,16 @@ class CtaEngineManager(QtGui.QWidget):
|
|||||||
savePositionButton.clicked.connect(self.ctaEngine.savePosition)
|
savePositionButton.clicked.connect(self.ctaEngine.savePosition)
|
||||||
|
|
||||||
# 滚动区域,放置所有的CtaStrategyManager
|
# 滚动区域,放置所有的CtaStrategyManager
|
||||||
self.scrollArea = QtGui.QScrollArea()
|
self.scrollArea = QtWidgets.QScrollArea()
|
||||||
self.scrollArea.setWidgetResizable(True)
|
self.scrollArea.setWidgetResizable(True)
|
||||||
|
|
||||||
# CTA组件的日志监控
|
# CTA组件的日志监控
|
||||||
self.ctaLogMonitor = QtGui.QTextEdit()
|
self.ctaLogMonitor = QtWidgets.QTextEdit()
|
||||||
self.ctaLogMonitor.setReadOnly(True)
|
self.ctaLogMonitor.setReadOnly(True)
|
||||||
self.ctaLogMonitor.setMaximumHeight(200)
|
self.ctaLogMonitor.setMaximumHeight(200)
|
||||||
|
|
||||||
# 设置布局
|
# 设置布局
|
||||||
hbox2 = QtGui.QHBoxLayout()
|
hbox2 = QtWidgets.QHBoxLayout()
|
||||||
hbox2.addWidget(loadButton)
|
hbox2.addWidget(loadButton)
|
||||||
hbox2.addWidget(initAllButton)
|
hbox2.addWidget(initAllButton)
|
||||||
hbox2.addWidget(startAllButton)
|
hbox2.addWidget(startAllButton)
|
||||||
@ -229,7 +227,7 @@ class CtaEngineManager(QtGui.QWidget):
|
|||||||
hbox2.addWidget(savePositionButton)
|
hbox2.addWidget(savePositionButton)
|
||||||
hbox2.addStretch()
|
hbox2.addStretch()
|
||||||
|
|
||||||
vbox = QtGui.QVBoxLayout()
|
vbox = QtWidgets.QVBoxLayout()
|
||||||
vbox.addLayout(hbox2)
|
vbox.addLayout(hbox2)
|
||||||
vbox.addWidget(self.scrollArea)
|
vbox.addWidget(self.scrollArea)
|
||||||
vbox.addWidget(self.ctaLogMonitor)
|
vbox.addWidget(self.ctaLogMonitor)
|
||||||
@ -238,8 +236,8 @@ class CtaEngineManager(QtGui.QWidget):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def initStrategyManager(self):
|
def initStrategyManager(self):
|
||||||
"""初始化策略管理组件界面"""
|
"""初始化策略管理组件界面"""
|
||||||
w = QtGui.QWidget()
|
w = QtWidgets.QWidget()
|
||||||
vbox = QtGui.QVBoxLayout()
|
vbox = QtWidgets.QVBoxLayout()
|
||||||
|
|
||||||
for name in self.ctaEngine.strategyDict.keys():
|
for name in self.ctaEngine.strategyDict.keys():
|
||||||
# 为每一个策略实例,创建对应的管理组件实例
|
# 为每一个策略实例,创建对应的管理组件实例
|
||||||
@ -292,19 +290,6 @@ class CtaEngineManager(QtGui.QWidget):
|
|||||||
self.signal.connect(self.updateCtaLog)
|
self.signal.connect(self.updateCtaLog)
|
||||||
self.eventEngine.register(EVENT_CTA_LOG, self.signal.emit)
|
self.eventEngine.register(EVENT_CTA_LOG, self.signal.emit)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def closeEvent(self, event):
|
|
||||||
"""关闭窗口时的事件"""
|
|
||||||
reply = QtGui.QMessageBox.question(self, text.SAVE_POSITION_DATA,
|
|
||||||
text.SAVE_POSITION_QUESTION, QtGui.QMessageBox.Yes |
|
|
||||||
QtGui.QMessageBox.No, QtGui.QMessageBox.No)
|
|
||||||
|
|
||||||
if reply == QtGui.QMessageBox.Yes:
|
|
||||||
self.ctaEngine.savePosition()
|
|
||||||
|
|
||||||
event.accept()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user