def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add vt_symbols and name edit if add new strategy if self.class_name: self.setWindowTitle(f"添加策略:{self.class_name}") button_text = "添加" parameters = {"strategy_name": "", "vt_symbols": ""} 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): """""" 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): """""" self.setWindowTitle("创建价差") self.name_line = QtWidgets.QLineEdit() self.active_line = QtWidgets.QLineEdit() self.min_volume_combo = QtWidgets.QComboBox() self.min_volume_combo.addItems([ "1", "0.1", "0.01", "0.001", "0.0001", "0.00001", "0.000001", ]) self.grid = QtWidgets.QGridLayout() button_add = QtWidgets.QPushButton("创建价差") button_add.clicked.connect(self.add_spread) Label = QtWidgets.QLabel grid = QtWidgets.QGridLayout() grid.addWidget(Label("价差名称"), 0, 0) grid.addWidget(self.name_line, 0, 1, 1, 4) grid.addWidget(Label("主动腿代码"), 1, 0) grid.addWidget(self.active_line, 1, 1, 1, 4) grid.addWidget(Label("最小交易量"), 2, 0) grid.addWidget(self.min_volume_combo, 2, 1, 1, 4) grid.addWidget(Label(""), 3, 0) grid.addWidget(Label("本地代码"), 4, 1) grid.addWidget(Label("价格乘数"), 4, 2) grid.addWidget(Label("交易乘数"), 4, 3) grid.addWidget(Label("合约模式"), 4, 4) int_validator = QtGui.QIntValidator() leg_count = 5 for i in range(leg_count): symbol_line = QtWidgets.QLineEdit() price_line = QtWidgets.QLineEdit() price_line.setValidator(int_validator) trading_line = QtWidgets.QLineEdit() trading_line.setValidator(int_validator) inverse_combo = QtWidgets.QComboBox() inverse_combo.addItems(["正向", "反向"]) grid.addWidget(Label("腿{}".format(i + 1)), 5 + i, 0) grid.addWidget(symbol_line, 5 + i, 1) grid.addWidget(price_line, 5 + i, 2) grid.addWidget(trading_line, 5 + i, 3) grid.addWidget(inverse_combo, 5 + i, 4) d = { "symbol": symbol_line, "price": price_line, "trading": trading_line, "inverse": inverse_combo } self.leg_widgets.append(d) grid.addWidget( Label(""), 5 + leg_count, 0, ) grid.addWidget(button_add, 6 + leg_count, 0, 1, 5) self.setLayout(grid)
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)