def init_ui(self): """""" self.setWindowTitle("CTA策略") # Create widgets self.class_combo = QtWidgets.QComboBox() add_button = QtWidgets.QPushButton("添加策略") add_button.clicked.connect(self.add_strategy) init_button = QtWidgets.QPushButton("全部初始化") init_button.clicked.connect(self.cta_engine.init_all_strategies) start_button = QtWidgets.QPushButton("全部启动") start_button.clicked.connect(self.cta_engine.start_all_strategies) stop_button = QtWidgets.QPushButton("全部停止") stop_button.clicked.connect(self.cta_engine.stop_all_strategies) clear_button = QtWidgets.QPushButton("清空日志") clear_button.clicked.connect(self.clear_log) self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) self.log_monitor = LogMonitor(self.main_engine, self.event_engine) # self.stop_order_monitor = StopOrderMonitor( # self.main_engine, self.event_engine # ) # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(self.class_combo) hbox1.addWidget(add_button) hbox1.addStretch() hbox1.addWidget(init_button) hbox1.addWidget(start_button) hbox1.addWidget(stop_button) hbox1.addWidget(clear_button) grid = QtWidgets.QGridLayout() grid.addWidget(scroll_area, 0, 0, 2, 1) #grid.addWidget(self.stop_order_monitor, 0, 1) grid.addWidget(self.log_monitor, 1, 1) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(grid) self.setLayout(vbox)
def init_ui(self) -> None: """""" self.setWindowTitle("组合策略") # Create widgets self.class_combo = QtWidgets.QComboBox() add_button = QtWidgets.QPushButton("添加策略") add_button.clicked.connect(self.add_strategy) init_button = QtWidgets.QPushButton("全部初始化") init_button.clicked.connect(self.strategy_engine.init_all_strategies) start_button = QtWidgets.QPushButton("全部启动") start_button.clicked.connect(self.strategy_engine.start_all_strategies) stop_button = QtWidgets.QPushButton("全部停止") stop_button.clicked.connect(self.strategy_engine.stop_all_strategies) clear_button = QtWidgets.QPushButton("清空日志") clear_button.clicked.connect(self.clear_log) self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) self.log_monitor = LogMonitor(self.main_engine, self.event_engine) # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(self.class_combo) hbox1.addWidget(add_button) hbox1.addStretch() hbox1.addWidget(init_button) hbox1.addWidget(start_button) hbox1.addWidget(stop_button) hbox1.addWidget(clear_button) hbox2 = QtWidgets.QHBoxLayout() hbox2.addWidget(scroll_area) hbox2.addWidget(self.log_monitor) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) self.setLayout(vbox)
def init_ui(self): """""" self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll_area) self.setLayout(vbox)
def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add vt_symbol and name edit if add new strategy if self.class_name: self.setWindowTitle(f"添加策略:{self.class_name}") button_text = "添加" parameters = {"strategy_name": "", "vt_symbol": ""} parameters.update(self.parameters) else: self.setWindowTitle(f"参数编辑:{self.strategy_name}") button_text = "确定" parameters = self.parameters for name, value in parameters.items(): type_ = type(value) edit = QtWidgets.QLineEdit(str(value)) if type_ is int: validator = QtGui.QIntValidator() edit.setValidator(validator) elif type_ is float: validator = QtGui.QDoubleValidator() edit.setValidator(validator) form.addRow(f"{name} {type_}", edit) self.edits[name] = (edit, type_) button = QtWidgets.QPushButton(button_text) button.clicked.connect(self.accept) form.addRow(button) widget = QtWidgets.QWidget() widget.setLayout(form) scroll = QtWidgets.QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll) self.setLayout(vbox)
def init_ui(self): """""" QLabel = QtWidgets.QLabel self.target_combo = QtWidgets.QComboBox() self.target_combo.addItems(list(self.DISPLAY_NAME_MAP.keys())) grid = QtWidgets.QGridLayout() grid.addWidget(QLabel("目标"), 0, 0) grid.addWidget(self.target_combo, 0, 1, 1, 3) grid.addWidget(QLabel("参数"), 1, 0) grid.addWidget(QLabel("开始"), 1, 1) grid.addWidget(QLabel("步进"), 1, 2) grid.addWidget(QLabel("结束"), 1, 3) # Add vt_symbol and name edit if add new strategy self.setWindowTitle(f"优化参数配置:{self.class_name}") validator = QtGui.QDoubleValidator() row = 2 for name, value in self.parameters.items(): type_ = type(value) if type_ not in [int, float]: continue start_edit = QtWidgets.QLineEdit(str(value)) step_edit = QtWidgets.QLineEdit(str(1)) end_edit = QtWidgets.QLineEdit(str(value)) for edit in [start_edit, step_edit, end_edit]: edit.setValidator(validator) grid.addWidget(QLabel(name), row, 0) grid.addWidget(start_edit, row, 1) grid.addWidget(step_edit, row, 2) grid.addWidget(end_edit, row, 3) self.edits[name] = { "type": type_, "start": start_edit, "step": step_edit, "end": end_edit } row += 1 parallel_button = QtWidgets.QPushButton("多进程优化") parallel_button.clicked.connect(self.generate_parallel_setting) grid.addWidget(parallel_button, row, 0, 1, 4) row += 1 ga_button = QtWidgets.QPushButton("遗传算法优化") ga_button.clicked.connect(self.generate_ga_setting) grid.addWidget(ga_button, row, 0, 1, 4) widget = QtWidgets.QWidget() widget.setLayout(grid) scroll = QtWidgets.QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("算法交易") # Left side control widgets self.template_combo = QtWidgets.QComboBox() self.template_combo.currentIndexChanged.connect(self.show_algo_widget) form = QtWidgets.QFormLayout() form.addRow("算法", self.template_combo) widget = QtWidgets.QWidget() widget.setLayout(form) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(widget) for algo_template in self.algo_engine.algo_templates.values(): widget = AlgoWidget(self.algo_engine, algo_template) vbox.addWidget(widget) template_name = algo_template.__name__ display_name = algo_template.display_name self.algo_widgets[template_name] = widget self.template_combo.addItem(display_name, template_name) vbox.addStretch() stop_all_button = QtWidgets.QPushButton("全部停止") stop_all_button.setFixedHeight(stop_all_button.sizeHint().height() * 2) stop_all_button.clicked.connect(self.algo_engine.stop_all) vbox.addWidget(stop_all_button) # Right side monitor widgets active_algo_monitor = ActiveAlgoMonitor( self.algo_engine, self.event_engine ) inactive_algo_monitor = InactiveAlgoMonitor( self.algo_engine, self.event_engine ) tab1 = QtWidgets.QTabWidget() tab1.addTab(active_algo_monitor, "执行中") tab1.addTab(inactive_algo_monitor, "已结束") log_monitor = LogMonitor(self.event_engine) tab2 = QtWidgets.QTabWidget() tab2.addTab(log_monitor, "日志") setting_monitor = SettingMonitor(self.algo_engine, self.event_engine) setting_monitor.use_signal.connect(self.use_setting) tab3 = QtWidgets.QTabWidget() tab3.addTab(setting_monitor, "配置") grid = QtWidgets.QGridLayout() grid.addWidget(tab1, 0, 0, 1, 2) grid.addWidget(tab2, 1, 0) grid.addWidget(tab3, 1, 1) hbox2 = QtWidgets.QHBoxLayout() hbox2.addLayout(vbox) hbox2.addLayout(grid) self.setLayout(hbox2) self.show_algo_widget()