def init_ui(self): """""" self.name_line = QtWidgets.QLineEdit() self.symbol_line = QtWidgets.QLineEdit() self.remove_combo = QtWidgets.QComboBox() for w in [self.name_line, self.symbol_line, self.remove_combo]: w.setFixedWidth(150) add_button = QtWidgets.QPushButton("创建策略") add_button.clicked.connect(self.add_strategy) remove_button = QtWidgets.QPushButton("移除策略") remove_button.clicked.connect(self.remove_strategy) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("策略名称")) hbox.addWidget(self.name_line) hbox.addWidget(QtWidgets.QLabel("交易合约")) hbox.addWidget(self.symbol_line) hbox.addWidget(add_button) hbox.addStretch() hbox.addWidget(self.remove_combo) hbox.addWidget(remove_button) self.setLayout(hbox)
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): """ Initialize line edits and form layout based on setting. """ self.setMaximumWidth(400) form = QtWidgets.QFormLayout() for field_name, field_value in self.default_setting.items(): field_type = type(field_value) if field_type == list: widget = QtWidgets.QComboBox() widget.addItems(field_value) else: widget = QtWidgets.QLineEdit() display_name = NAME_DISPLAY_MAP.get(field_name, field_name) form.addRow(display_name, widget) self.widgets[field_name] = (widget, field_type) start_algo_button = QtWidgets.QPushButton("启动算法") start_algo_button.clicked.connect(self.start_algo) form.addRow(start_algo_button) load_csv_button = QtWidgets.QPushButton("CSV启动") load_csv_button.clicked.connect(self.load_csv) form.addRow(load_csv_button) form.addRow(QtWidgets.QLabel("")) form.addRow(QtWidgets.QLabel("")) form.addRow(QtWidgets.QLabel("")) self.setting_name_line = QtWidgets.QLineEdit() form.addRow("配置名称", self.setting_name_line) save_setting_button = QtWidgets.QPushButton("保存配置") save_setting_button.clicked.connect(self.save_setting) form.addRow(save_setting_button) for button in [ start_algo_button, load_csv_button, save_setting_button ]: button.setFixedHeight(button.sizeHint().height() * 2) self.setLayout(form)
def init_ui(self): """""" self.setFixedHeight(300) self.setFrameShape(self.Box) self.setLineWidth(1) init_button = QtWidgets.QPushButton("初始化") init_button.clicked.connect(self.init_strategy) start_button = QtWidgets.QPushButton("启动") start_button.clicked.connect(self.start_strategy) stop_button = QtWidgets.QPushButton("停止") stop_button.clicked.connect(self.stop_strategy) edit_button = QtWidgets.QPushButton("编辑") edit_button.clicked.connect(self.edit_strategy) remove_button = QtWidgets.QPushButton("移除") remove_button.clicked.connect(self.remove_strategy) strategy_name = self._data["strategy_name"] spread_name = self._data["spread_name"] class_name = self._data["class_name"] author = self._data["author"] label_text = ( f"{strategy_name} - {spread_name} ({class_name} by {author})" ) label = QtWidgets.QLabel(label_text) label.setAlignment(QtCore.Qt.AlignCenter) self.parameters_monitor = StrategyDataMonitor(self._data["parameters"]) self.variables_monitor = StrategyDataMonitor(self._data["variables"]) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(init_button) hbox.addWidget(start_button) hbox.addWidget(stop_button) hbox.addWidget(edit_button) hbox.addWidget(remove_button) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(label) vbox.addLayout(hbox) vbox.addWidget(self.parameters_monitor) vbox.addWidget(self.variables_monitor) self.setLayout(vbox)
def init_ui(self) -> None: """""" self.setWindowTitle("K线图表") self.tab: QtWidgets.QTabWidget = QtWidgets.QTabWidget() self.symbol_line: QtWidgets.QLineEdit = QtWidgets.QLineEdit() self.button = QtWidgets.QPushButton("新建图表") self.button.clicked.connect(self.new_chart) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("本地代码")) hbox.addWidget(self.symbol_line) hbox.addWidget(self.button) hbox.addStretch() vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget(self.tab) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("行情记录") self.resize(1000, 600) # Create widgets self.symbol_line = QtWidgets.QLineEdit() self.symbol_line.setFixedHeight(self.symbol_line.sizeHint().height() * 2) contracts = self.main_engine.get_all_contracts() self.vt_symbols = [contract.vt_symbol for contract in contracts] self.symbol_completer = QtWidgets.QCompleter(self.vt_symbols) self.symbol_completer.setFilterMode(QtCore.Qt.MatchContains) self.symbol_completer.setCompletionMode( self.symbol_completer.PopupCompletion) self.symbol_line.setCompleter(self.symbol_completer) add_bar_button = QtWidgets.QPushButton("添加") add_bar_button.clicked.connect(self.add_bar_recording) remove_bar_button = QtWidgets.QPushButton("移除") remove_bar_button.clicked.connect(self.remove_bar_recording) add_tick_button = QtWidgets.QPushButton("添加") add_tick_button.clicked.connect(self.add_tick_recording) remove_tick_button = QtWidgets.QPushButton("移除") remove_tick_button.clicked.connect(self.remove_tick_recording) self.bar_recording_edit = QtWidgets.QTextEdit() self.bar_recording_edit.setReadOnly(True) self.tick_recording_edit = QtWidgets.QTextEdit() self.tick_recording_edit.setReadOnly(True) self.log_edit = QtWidgets.QTextEdit() self.log_edit.setReadOnly(True) # Set layout grid = QtWidgets.QGridLayout() grid.addWidget(QtWidgets.QLabel("K线记录"), 0, 0) grid.addWidget(add_bar_button, 0, 1) grid.addWidget(remove_bar_button, 0, 2) grid.addWidget(QtWidgets.QLabel("Tick记录"), 1, 0) grid.addWidget(add_tick_button, 1, 1) grid.addWidget(remove_tick_button, 1, 2) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("本地代码")) hbox.addWidget(self.symbol_line) hbox.addWidget(QtWidgets.QLabel(" ")) hbox.addLayout(grid) hbox.addStretch() grid2 = QtWidgets.QGridLayout() grid2.addWidget(QtWidgets.QLabel("K线记录列表"), 0, 0) grid2.addWidget(QtWidgets.QLabel("Tick记录列表"), 0, 1) grid2.addWidget(self.bar_recording_edit, 1, 0) grid2.addWidget(self.tick_recording_edit, 1, 1) grid2.addWidget(self.log_edit, 2, 0, 1, 2) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(grid2) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("回测K线图表") self.resize(1400, 800) # Create chart widget self.chart = ChartWidget() self.chart.add_plot("candle", hide_x_axis=True) self.chart.add_plot("volume", maximum_height=200) self.chart.add_item(CandleItem, "candle", "candle") self.chart.add_item(VolumeItem, "volume", "volume") self.chart.add_cursor() # Create help widget text1 = "红色虚线 —— 盈利交易" label1 = QtWidgets.QLabel(text1) label1.setStyleSheet("color:red") text2 = "绿色虚线 —— 亏损交易" label2 = QtWidgets.QLabel(text2) label2.setStyleSheet("color:#00FF00") text3 = "黄色向上箭头 —— 买入开仓 Buy" label3 = QtWidgets.QLabel(text3) label3.setStyleSheet("color:yellow") text4 = "黄色向下箭头 —— 卖出平仓 Sell" label4 = QtWidgets.QLabel(text4) label4.setStyleSheet("color:yellow") text5 = "紫红向下箭头 —— 卖出开仓 Short" label5 = QtWidgets.QLabel(text5) label5.setStyleSheet("color:magenta") text6 = "紫红向上箭头 —— 买入平仓 Cover" label6 = QtWidgets.QLabel(text6) label6.setStyleSheet("color:magenta") hbox1 = QtWidgets.QHBoxLayout() hbox1.addStretch() hbox1.addWidget(label1) hbox1.addStretch() hbox1.addWidget(label2) hbox1.addStretch() hbox2 = QtWidgets.QHBoxLayout() hbox2.addStretch() hbox2.addWidget(label3) hbox2.addStretch() hbox2.addWidget(label4) hbox2.addStretch() hbox3 = QtWidgets.QHBoxLayout() hbox3.addStretch() hbox3.addWidget(label5) hbox3.addStretch() hbox3.addWidget(label6) hbox3.addStretch() # Set layout vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.chart) vbox.addLayout(hbox1) vbox.addLayout(hbox2) vbox.addLayout(hbox3) self.setLayout(vbox)