def __init__(self, ctaEngine, eventEngine, name, className=None, direction=None, vtSymbol=None, longsymbol=None, shortsymbol=None, parent=None): """Constructor""" super(CtaStrategyManager, self).__init__(parent) self.ctaEngine = ctaEngine self.eventEngine = eventEngine self.name = name self.initUi() self.updateMonitor() self.registerEvent() if className == 'tradeTest': self.paramWindow = ParamWindow(self.name, longsymbol, shortsymbol) elif className == "CtpAndIB": self.paramWindow = ParamWindow3(self.name, longsymbol, shortsymbol) else: self.paramWindow = ParamWindow2(self.name, direction, vtSymbol)
def addStrategy(self): self.pw = ParamWindow("", "", "", self.ctaEngine) self.gt = ParamWindow2("", "", "", self.ctaEngine) self.cai = ParamWindow3("", "", "", self.ctaEngine) self.abt = ParamWindow4("", "", "", self.ctaEngine) self.sw = strategyWindow(self.pw, self.gt, self.cai, self.abt) self.sw.show()
def __init__(self, ctaEngine, eventEngine, parent=None): """Constructor""" super(CtaEngineManager, self).__init__(parent) self.ctaEngine = ctaEngine self.eventEngine = eventEngine self.strategyLoaded = False self.pw = ParamWindow("", "", "", self) self.gt = ParamWindow2("", "", "", self) self.cai = ParamWindow3("", "", "", self) #self.sw = strategyWindow(self.pw, self.gt,self.cai) self.initUi() self.registerEvent() # 记录日志 self.ctaEngine.writeCtaLog(u'CTA引擎启动成功')
def addStrategy(self): self.pw = ParamWindow("", "", "", self) self.gt = ParamWindow2("", "", "", self) self.cai = ParamWindow3("", "", "", self) self.sw = strategyWindow(self.pw, self.gt, self.cai) self.sw.show()
class CtaStrategyManager(QtGui.QGroupBox): """策略管理组件""" signal = QtCore.pyqtSignal(type(Event())) #---------------------------------------------------------------------- def __init__(self, ctaEngine, eventEngine, name, className=None, direction=None, vtSymbol=None, longsymbol=None, shortsymbol=None, parent=None): """Constructor""" super(CtaStrategyManager, self).__init__(parent) self.ctaEngine = ctaEngine self.eventEngine = eventEngine self.name = name self.initUi() self.updateMonitor() self.registerEvent() if className == 'tradeTest': self.paramWindow = ParamWindow(self.name, longsymbol, shortsymbol) elif className == "CtpAndIB": self.paramWindow = ParamWindow3(self.name, longsymbol, shortsymbol) else: self.paramWindow = ParamWindow2(self.name, direction, vtSymbol) #---------------------------------------------------------------------- def initUi(self): """初始化界面""" self.setTitle(self.name) self.paramMonitor = CtaValueMonitor(self) self.varMonitor = CtaValueMonitor(self) maxHeight = 60 self.paramMonitor.setMaximumHeight(maxHeight) self.varMonitor.setMaximumHeight(maxHeight) buttonInit = QtGui.QPushButton(u'初始化') buttonStart = QtGui.QPushButton(u'启动') buttonStop = QtGui.QPushButton(u'停止') buttonParam = QtGui.QPushButton(u'参数') buttonDelete = QtGui.QPushButton(u'删除') buttonDelete.clicked.connect(self.delete) buttonInit.clicked.connect(self.init) buttonStart.clicked.connect(self.start) buttonStop.clicked.connect(self.stop) buttonParam.clicked.connect(self.param) hbox1 = QtGui.QHBoxLayout() hbox1.addWidget(buttonInit) hbox1.addWidget(buttonStart) hbox1.addWidget(buttonStop) hbox1.addWidget(buttonParam) hbox1.addWidget(buttonDelete) hbox1.addStretch() hbox2 = QtGui.QHBoxLayout() hbox2.addWidget(self.paramMonitor) hbox3 = QtGui.QHBoxLayout() hbox3.addWidget(self.varMonitor) vbox = QtGui.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) vbox.addLayout(hbox3) self.setLayout(vbox) #---------------------------------------------------------------------- def updateMonitor(self, event=None): """显示策略最新状态""" paramDict = self.ctaEngine.getStrategyParam(self.name) if paramDict: self.paramMonitor.updateData(paramDict) self.paramMonitor.setColumnWidth(3, 300) varDict = self.ctaEngine.getStrategyVar(self.name) if varDict: self.varMonitor.updateData(varDict) self.varMonitor.setColumnWidth(3, 300) #---------------------------------------------------------------------- def registerEvent(self): """注册事件监听""" self.signal.connect(self.updateMonitor) self.eventEngine.register(EVENT_CTA_STRATEGY + self.name, self.signal.emit) #---------------------------------------------------------------------- def init(self): """初始化策略""" self.ctaEngine.initStrategy(self.name) #---------------------------------------------------------------------- def start(self): """启动策略""" self.ctaEngine.startStrategy(self.name) #---------------------------------------------------------------------- def stop(self): """停止策略""" self.ctaEngine.stopStrategy(self.name) #========================================================================================== def param(self): self.paramWindow.paramters = self.paramWindow.loadParameter() self.paramWindow.showParam() self.paramWindow.show() #def position(self): #self.ctaEngine.excPos(self.name) #def updateInfo(self): #self.ctaEngine.loadPosInfo() def delete(self): settingFileName = 'ctaAlgo/CTA_setting.json' reply = QtGui.QMessageBox.question( self, u'删除', u'是否删除配置文件?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) with open(settingFileName, 'r') as f: l = json.load(f) f.close() #flag = True for x in l: if x['name'] == self.name: l.remove(x) #flag = False with open(settingFileName, 'w') as f: json.dump(l, f) f.close() if reply == QtGui.QMessageBox.Yes: fileName = "parameter_" + self.name + ".json" os.remove(fileName) else: pass0