def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add spread_name and name edit if add new strategy if self.class_name: self.setWindowTitle(f"添加策略:{self.class_name}") button_text = "添加" parameters = {"strategy_name": "", "spread_name": ""} 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) self.setLayout(form)
def init_ui(self): """""" self.name_combo = QtWidgets.QComboBox() self.direction_combo = QtWidgets.QComboBox() self.direction_combo.addItems( [Direction.LONG.value, Direction.SHORT.value]) self.offset_combo = QtWidgets.QComboBox() self.offset_combo.addItems([offset.value for offset in Offset]) double_validator = QtGui.QDoubleValidator() double_validator.setBottom(0) self.price_line = QtWidgets.QLineEdit() self.price_line.setValidator(double_validator) self.volume_line = QtWidgets.QLineEdit() self.volume_line.setValidator(double_validator) for w in [ self.name_combo, self.price_line, self.volume_line, self.direction_combo, self.offset_combo ]: w.setFixedWidth(150) send_button = QtWidgets.QPushButton("委托") send_button.clicked.connect(self.send_order) send_button.setFixedWidth(70) cancel_button = QtWidgets.QPushButton("全撤") cancel_button.clicked.connect(self.cancel_all) cancel_button.setFixedWidth(70) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("策略名称")) hbox.addWidget(self.name_combo) hbox.addWidget(QtWidgets.QLabel("方向")) hbox.addWidget(self.direction_combo) hbox.addWidget(QtWidgets.QLabel("开平")) hbox.addWidget(self.offset_combo) hbox.addWidget(QtWidgets.QLabel("价格")) hbox.addWidget(self.price_line) hbox.addWidget(QtWidgets.QLabel("数量")) hbox.addWidget(self.volume_line) hbox.addWidget(send_button) hbox.addWidget(cancel_button) hbox.addStretch() self.setLayout(hbox)
def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add vt_symbol and name edit if add new strategy self.setWindowTitle(f"策略参数配置:{self.class_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("启动算法") self.setFrameShape(self.Box) self.setLineWidth(1) self.name_line = QtWidgets.QLineEdit() self.direction_combo = QtWidgets.QComboBox() self.direction_combo.addItems( [Direction.LONG.value, Direction.SHORT.value] ) self.offset_combo = QtWidgets.QComboBox() self.offset_combo.addItems( [Offset.NONE.value, Offset.OPEN.value, Offset.CLOSE.value] ) float_validator = QtGui.QDoubleValidator() self.price_line = QtWidgets.QLineEdit() self.price_line.setValidator(float_validator) self.volume_line = QtWidgets.QLineEdit() self.volume_line.setValidator(float_validator) int_validator = QtGui.QIntValidator() self.payup_line = QtWidgets.QLineEdit() self.payup_line.setValidator(int_validator) self.interval_line = QtWidgets.QLineEdit() self.interval_line.setValidator(int_validator) button_start = QtWidgets.QPushButton("启动") button_start.clicked.connect(self.start_algo) self.lock_combo = QtWidgets.QComboBox() self.lock_combo.addItems( ["否", "是"] ) 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) add_spread_button = QtWidgets.QPushButton("创建价差") add_spread_button.clicked.connect(self.add_spread) remove_spread_button = QtWidgets.QPushButton("移除价差") remove_spread_button.clicked.connect(self.remove_spread) form = QtWidgets.QFormLayout() form.addRow("价差", self.name_line) form.addRow("方向", self.direction_combo) form.addRow("开平", self.offset_combo) form.addRow("价格", self.price_line) form.addRow("数量", self.volume_line) form.addRow("超价", self.payup_line) form.addRow("间隔", self.interval_line) form.addRow("锁仓", self.lock_combo) form.addRow(button_start) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addStretch() vbox.addWidget(self.class_combo) vbox.addWidget(add_button) vbox.addWidget(init_button) vbox.addWidget(start_button) vbox.addWidget(stop_button) vbox.addStretch() vbox.addWidget(add_spread_button) vbox.addWidget(remove_spread_button) self.setLayout(vbox)