def generatePicture(self): self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) # 白色 p.setPen(pg.mkPen('w')) prema5 = 0 prema10 = 0 prema20 = 0 for m in self.data: if prema5 != 0 and self.period == 5: # 白色 p.setPen(pg.mkPen('w')) p.setBrush(pg.mkBrush('w')) p.drawLine(QtCore.QPointF(m.t - 1, prema5), QtCore.QPointF(m.t, m.ma)) prema5 = m.ma if prema10 != 0 and self.period == 10: # 青色 p.setPen(pg.mkPen('c')) p.setBrush(pg.mkBrush('c')) p.drawLine(QtCore.QPointF(m.t - 1, prema10), QtCore.QPointF(m.t, m.ma)) prema10 = m.ma if prema20 != 0 and self.period == 20: # 品色 p.setPen(pg.mkPen('m')) p.setBrush(pg.mkBrush('m')) p.drawLine(QtCore.QPointF(m.t - 1, prema20), QtCore.QPointF(m.t, m.ma)) prema20 = m.ma p.end()
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" value = self.values[ix] last_value = self.values[ix - 1] # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Set painter color painter.setPen(self.yellow_pen) # painter.setBrush(self.yellow_brush) # Draw Line if np.isnan(last_value) or np.isnan(value): # print(ix - 1, last_value,ix, value,) pass else: start_point = QtCore.QPointF(ix - 1, last_value) end_point = QtCore.QPointF(ix, value) painter.drawLine(start_point, end_point) # Draw Circle # painter.drawEllipse(QtCore.QPointF(ix, self.values[ix]), 2, 2) # Finish painter.end() return picture
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" rsi_value = self.get_rsi_value(ix) last_rsi_value = self.get_rsi_value(ix - 1) # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Draw RSI line painter.setPen(self.yellow_pen) end_point = QtCore.QPointF(ix, rsi_value) start_point = QtCore.QPointF(ix - 1, last_rsi_value) painter.drawLine(start_point, end_point) # Draw oversold/overbought line painter.setPen(self.white_pen) painter.drawLine( QtCore.QPointF(ix, 70), QtCore.QPointF(ix - 1, 70), ) painter.drawLine( QtCore.QPointF(ix, 30), QtCore.QPointF(ix - 1, 30), ) # Finish painter.end() return picture
def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add spread_name and name edit if add new strategy if self.class_name: self.setWindowTitle(f" add strategy :{self.class_name}") button_text = " add to " parameters = {"strategy_name": "", "spread_name": ""} parameters.update(self.parameters) else: self.setWindowTitle(f" parameter editing :{self.strategy_name}") button_text = " determine " 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 _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" # Create objects volume_picture = QtGui.QPicture() painter = QtGui.QPainter(volume_picture) # Set painter color if bar.close_price >= bar.open_price: painter.setPen(self._up_pen) painter.setBrush(self._up_brush) else: painter.setPen(self._down_pen) painter.setBrush(self._down_brush) # Draw volume body rect = QtCore.QRectF( ix - BAR_WIDTH, 0, BAR_WIDTH * 2, bar.volume ) painter.drawRect(rect) # Finish painter.end() return volume_picture
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" # Create objects candle_picture = QtGui.QPicture() painter = QtGui.QPainter(candle_picture) # Set painter color if bar.close_price >= bar.open_price: painter.setPen(self._up_pen) painter.setBrush(self._up_brush) else: painter.setPen(self._down_pen) painter.setBrush(self._down_brush) # Draw candle shadow painter.drawLine(QtCore.QPointF(ix, bar.high_price), QtCore.QPointF(ix, bar.low_price)) # Draw candle body if bar.open_price == bar.close_price: painter.drawLine( QtCore.QPointF(ix - BAR_WIDTH, bar.open_price), QtCore.QPointF(ix + BAR_WIDTH, bar.open_price), ) else: rect = QtCore.QRectF(ix - BAR_WIDTH, bar.open_price, BAR_WIDTH * 2, bar.close_price - bar.open_price) painter.drawRect(rect) # Finish painter.end() return candle_picture
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) self.setLayout(form)
def _draw_item_picture(self, min_ix: int, max_ix: int) -> None: """ Draw the picture of item in specific range. """ self._item_picuture = QtGui.QPicture() painter = QtGui.QPainter(self._item_picuture) for n in range(min_ix, max_ix): bar_picture = self._bar_picutures[n] bar_picture.play(painter) painter.end()
def init_ui(self) -> None: """""" self.setMinimumWidth(300) self.setWindowTitle(f"添加【{self.rule_name}】雷达信号") self.type_combo = QtWidgets.QComboBox() self.type_combo.addItems([ SignalType.GREATER_THAN.value, SignalType.LESS_THAN.value, SignalType.EQUAL_TO.value, ]) self.target_line = QtWidgets.QLineEdit() self.target_line.setValidator(QtGui.QDoubleValidator()) self.sound_check = QtWidgets.QCheckBox() self.email_check = QtWidgets.QCheckBox() button = QtWidgets.QPushButton("添加") button.clicked.connect(self.add_signal) form = QtWidgets.QFormLayout() form.addRow("信号类型", self.type_combo) form.addRow("目标数值", self.target_line) form.addRow("声音通知", self.sound_check) form.addRow("邮件通知", self.email_check) form.addRow(button) self.setLayout(form)
def init_ui(self): self.setWindowTitle("锁仓单平仓") self.setMinimumWidth(300) self.symbol_combo = ComboBox() self.symbol_combo.pop_show.connect(self.refresh_symbol_list) self.symbol_combo.activated[str].connect(self.set_close_symbol) validator = QtGui.QIntValidator() self.close_pos_line = QtWidgets.QLineEdit() self.close_pos_line.setValidator(validator) button_close = QtWidgets.QPushButton("平仓") button_close.clicked.connect(self.close_hedged_pos) for btn in [button_close]: btn.setFixedHeight(btn.sizeHint().height() * 1.5) form = QtWidgets.QFormLayout() form.addRow("合约代码", self.symbol_combo) form.addRow("平仓手数", self.close_pos_line) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(button_close) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addLayout(hbox) self.setLayout(vbox)
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" # Create objects volume_picture = QtGui.QPicture() # painter = QtGui.QPainter(volume_picture) # Set painter color # if bar.close_price >= bar.open_price: # painter.setPen(self._up_pen) # painter.setBrush(self._up_brush) # else: # painter.setPen(self._down_pen) # painter.setBrush(self._down_brush) # # # Draw volume body # rect = QtCore.QRectF( # ix - BAR_WIDTH, # 0, # BAR_WIDTH * 2, # bar.volume # ) # painter.drawRect(rect) # # # Finish # painter.end() return volume_picture
def _draw_item_picture(self, min_ix: int, max_ix: int) -> None: """ Draw the picture of item in specific range. """ self._item_picuture = QtGui.QPicture() painter = QtGui.QPainter(self._item_picuture) for ix in range(min_ix, max_ix): bar_picture = self._bar_picutures[ix] if bar_picture is None: bar = self._manager.get_bar(ix) bar_picture = self._draw_bar_picture(ix, bar) self._bar_picutures[ix] = bar_picture bar_picture.play(painter) painter.end()
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) self.setLayout(grid)
def init_ui(self): """""" self.setWindowTitle("创建价差") self.name_line = QtWidgets.QLineEdit() self.active_line = QtWidgets.QLineEdit() 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, 3) grid.addWidget(Label("主动腿代码"), 1, 0) grid.addWidget(self.active_line, 1, 1, 1, 3) grid.addWidget(Label(""), 2, 0) grid.addWidget(Label("本地代码"), 3, 1) grid.addWidget(Label("价格乘数"), 3, 2) grid.addWidget(Label("交易乘数"), 3, 3) 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) grid.addWidget(Label("腿{}".format(i + 1)), 4 + i, 0) grid.addWidget(symbol_line, 4 + i, 1) grid.addWidget(price_line, 4 + i, 2) grid.addWidget(trading_line, 4 + i, 3) d = { "symbol": symbol_line, "price": price_line, "trading": trading_line } self.leg_widgets.append(d) grid.addWidget( Label(""), 4 + leg_count, 0, ) grid.addWidget(button_add, 5 + leg_count, 0, 1, 4) self.setLayout(grid)
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 _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" macd_value = self.get_macd_value(ix) last_macd_value = self.get_macd_value(ix - 1) # # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # # Draw macd lines if np.isnan(macd_value[0]) or np.isnan(last_macd_value[0]): # print("略过macd lines0") pass else: end_point0 = QtCore.QPointF(ix, macd_value[0]) start_point0 = QtCore.QPointF(ix - 1, last_macd_value[0]) painter.setPen(self.white_pen) painter.drawLine(start_point0, end_point0) if np.isnan(macd_value[1]) or np.isnan(last_macd_value[1]): # print("略过macd lines1") pass else: end_point1 = QtCore.QPointF(ix, macd_value[1]) start_point1 = QtCore.QPointF(ix - 1, last_macd_value[1]) painter.setPen(self.yellow_pen) painter.drawLine(start_point1, end_point1) if not np.isnan(macd_value[2]): if (macd_value[2] > 0): painter.setPen(self.red_pen) painter.setBrush(pg.mkBrush(255, 0, 0)) else: painter.setPen(self.green_pen) painter.setBrush(pg.mkBrush(0, 255, 0)) painter.drawRect(QtCore.QRectF(ix - 0.3, 0, 0.6, macd_value[2])) else: # print("略过macd lines2") pass painter.end() return picture
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" sma_value = self.get_sma_value(ix) last_sma_value = self.get_sma_value(ix - 1) # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Set painter color painter.setPen(self.blue_pen) # Draw Line start_point = QtCore.QPointF(ix-1, last_sma_value) end_point = QtCore.QPointF(ix, sma_value) painter.drawLine(start_point, end_point) # Finish painter.end() return picture
def init_ui(self): """""" self.setWindowTitle("期权交易") self.symbol_line = QtWidgets.QLineEdit() float_validator = QtGui.QDoubleValidator() float_validator.setBottom(0) self.price_line = QtWidgets.QLineEdit() self.price_line.setValidator(float_validator) int_validator = QtGui.QIntValidator() int_validator.setBottom(0) self.volume_line = QtWidgets.QLineEdit() self.volume_line.setValidator(int_validator) 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.OPEN.value, Offset.CLOSE.value]) order_button = QtWidgets.QPushButton("委托") order_button.clicked.connect(self.send_order) cancel_button = QtWidgets.QPushButton("全撤") cancel_button.clicked.connect(self.cancel_all) form = QtWidgets.QFormLayout() form.addRow("代码", self.symbol_line) form.addRow("方向", self.direction_combo) form.addRow("开平", self.offset_combo) form.addRow("价格", self.price_line) form.addRow("数量", self.volume_line) form.addRow(order_button) form.addRow(cancel_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): # 设置编码格式为utf-8 self.setUtf8(True) # 设置以'\n'换行 self.setEolMode(self.SC_EOL_LF) # 设置自动换行 self.setWrapMode(self.WrapWord) # 设置默认字体 self.setFont(self.font) # 设置tab键功能 self.setTabWidth(4) # Tab等于4个空格 self.setIndentationsUseTabs(True) # 行首缩进采用Tab键,反向缩进是Shift+Tab self.setIndentationWidth(4) # 行首缩进宽度为4个空格 self.setIndentationGuides(True) # 显示虚线垂直线的方式来指示缩进 self.setAutoIndent(True) # 插入新行时,自动缩进将光标推送到与前一个相同的缩进级别 # 设置光标 self.setCaretWidth(2) # 光标宽度(以像素为单位),0表示不显示光标 self.setCaretForegroundColor(QtGui.QColor("#ff0000ff")) # 设置光标前景色 self.setCaretLineVisible(True) # 设置是否使用光标所在行背景色 self.setCaretLineBackgroundColor(QtGui.QColor('#FFCFCF')) # 光标所在行的底色 # 设置页边,有3种Margin:0-行号; 1-改动标识; 2-代码折叠 self.setMarginsFont(self.font) # 行号字体 self.setMarginLineNumbers(0, True) # 设置标号为0的页边显示行号 self.setMarginWidth(0, '000') # 行号宽度 # self.setMarginBackgroundColor() # 设置页边背景颜色,这个api不会用 # 设置自动补全 # self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) # 对于所有Ascii码补全 # self.setAutoCompletionCaseSensitivity(False) # 取消自动补全大小写敏感 # self.setAutoCompletionThreshold(1) # 输入1个字符,就出现自动补全提示 # # 设置窗口大小 # self.setFixedSize(1024, 760) # 设置文档窗口的标题 self.setWindowTitle("MyEditor")
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" boll_value = self.get_boll_value(ix) last_boll_value = self.get_boll_value(ix - 1) # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Set painter color painter.setPen(self.blue_pen) if last_boll_value==0: # Draw Line start_point = QtCore.QPointF(0, 0) end_point = QtCore.QPointF(0, 0) painter.drawLine(start_point, end_point) else: # Draw Line start_point = QtCore.QPointF(ix-1, last_boll_value["upper"]) end_point = QtCore.QPointF(ix, boll_value["upper"]) painter.drawLine(start_point, end_point) start_point = QtCore.QPointF(ix-1, last_boll_value["lower"]) end_point = QtCore.QPointF(ix, boll_value["lower"]) painter.drawLine(start_point, end_point) start_point = QtCore.QPointF(ix-1, last_boll_value["middle"]) end_point = QtCore.QPointF(ix, boll_value["middle"]) painter.setPen(self.white_pen) painter.drawLine(start_point, end_point) # Finish painter.end() return picture
def __init__(self, parent=None): super(MyLangEditor, self).__init__(parent=parent) # 默认字体 self.font = QtGui.QFont("Courier", 16) # 词法解析器 self.lexer = Lexer(parent=self) self.lexer.setFont(self.font) self.setLexer(self.lexer) # 标志内容是否发生改变 self.text_change = False self.init_ui()
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" rsi_value = self.values[ix] last_rsi_value = self.values[ix - 1] # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Draw RSI line painter.setPen(self.yellow_pen) if np.isnan(last_rsi_value) or np.isnan(rsi_value): # print(ix - 1, last_rsi_value,ix, rsi_value,) pass else: end_point = QtCore.QPointF(ix, rsi_value) start_point = QtCore.QPointF(ix - 1, last_rsi_value) painter.drawLine(start_point, end_point) # Draw oversold/overbought line painter.setPen(self.white_pen) painter.drawLine( QtCore.QPointF(ix, 70), QtCore.QPointF(ix - 1, 70), ) painter.drawLine( QtCore.QPointF(ix, 30), QtCore.QPointF(ix - 1, 30), ) # Finish painter.end() return picture
def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture: """""" last_bar = self._manager.get_bar(ix - 1) # Create objects picture = QtGui.QPicture() painter = QtGui.QPainter(picture) # Set painter color painter.setPen(self.white_pen) # Draw Line end_point = QtCore.QPointF(ix, bar.close_price) if last_bar: start_point = QtCore.QPointF(ix - 1, last_bar.close_price) else: start_point = end_point painter.drawLine(start_point, end_point) # Finish painter.end() return picture
def highlightCurrentLine(self): extraSelections = [] if not self.isReadOnly(): selection = QtWidgets.QTextEdit.ExtraSelection() lineColor = QtGui.QColor(Qt.yellow).lighter(160) selection.format.setBackground(lineColor) selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() extraSelections.append(selection) self.setExtraSelections(extraSelections)
def init_ui(self): """""" form = QtWidgets.QFormLayout() for key, column_name_list in self.column_name_combo_dict.items(): column_name_combo = QtWidgets.QComboBox() for column_name in column_name_list: column_name_combo.addItem(f'{column_name}', column_name) self.column_name_combo_dict[key] = column_name_combo form.addRow(key, column_name_combo) # 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) self.setLayout(form)
def init_ui(self): self.setWindowTitle("修改仓位") self.setMinimumWidth(300) self.symbol_combo = ComboBox() self.symbol_combo.pop_show.connect(self.refresh_symbol_list) self.symbol_combo.activated[str].connect(self.set_modify_symbol) validator = QtGui.QIntValidator() # self.long_pos_line = QtWidgets.QLineEdit() # self.long_pos_line.setValidator(validator) # self.short_pos_line = QtWidgets.QLineEdit() # self.short_pos_line.setValidator(validator) self.basic_delta_line = QtWidgets.QLineEdit() self.basic_delta_line.setValidator(validator) self.traded_net_line = QtWidgets.QLineEdit() self.traded_net_line.setValidator(validator) self.lost_follow_line = QtWidgets.QLineEdit() self.lost_follow_line.setValidator(validator) button_modify = QtWidgets.QPushButton("修改") button_modify.clicked.connect(self.modify) for btn in [button_modify]: btn.setFixedHeight(btn.sizeHint().height() * 1.5) form = QtWidgets.QFormLayout() form.addRow("合约代码", self.symbol_combo) # form.addRow("目标户多仓", self.long_pos_line) # form.addRow("目标户空仓", self.short_pos_line) form.addRow("底仓差", self.basic_delta_line) form.addRow("交易净仓", self.traded_net_line) form.addRow("丢失净仓", self.lost_follow_line) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(button_modify) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addLayout(hbox) self.setLayout(vbox)
def lineNumberAreaPaintEvent(self, event): mypainter = QtGui.QPainter(self.lineNumberArea) mypainter.fillRect(event.rect(), Qt.lightGray) block = self.firstVisibleBlock() blockNumber = block.blockNumber() top = self.blockBoundingGeometry(block).translated( self.contentOffset()).top() bottom = top + self.blockBoundingRect(block).height() # Just to make sure I use the right font height = self.fontMetrics().height() while block.isValid() and (top <= event.rect().bottom()): if block.isVisible() and (bottom >= event.rect().top()): number = str(blockNumber + 1) mypainter.setPen(Qt.black) mypainter.drawText(0, top, self.lineNumberArea.width(), height, Qt.AlignRight, number) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() blockNumber += 1
def init_ui(self) -> None: """""" self.setWindowTitle("期权交易") # Trading Area self.symbol_line = QtWidgets.QLineEdit() self.symbol_line.returnPressed.connect(self._update_symbol) float_validator = QtGui.QDoubleValidator() float_validator.setBottom(0) self.price_line = QtWidgets.QLineEdit() self.price_line.setValidator(float_validator) int_validator = QtGui.QIntValidator() int_validator.setBottom(0) self.volume_line = QtWidgets.QLineEdit() self.volume_line.setValidator(int_validator) 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.OPEN.value, Offset.CLOSE.value]) order_button = QtWidgets.QPushButton("委托") order_button.clicked.connect(self.send_order) cancel_button = QtWidgets.QPushButton("全撤") cancel_button.clicked.connect(self.cancel_all) form1 = QtWidgets.QFormLayout() form1.addRow("代码", self.symbol_line) form1.addRow("方向", self.direction_combo) form1.addRow("开平", self.offset_combo) form1.addRow("价格", self.price_line) form1.addRow("数量", self.volume_line) form1.addRow(order_button) form1.addRow(cancel_button) # Depth Area bid_color = "rgb(255,174,201)" ask_color = "rgb(160,255,160)" self.bp1_label = self.create_label(bid_color) self.bp2_label = self.create_label(bid_color) self.bp3_label = self.create_label(bid_color) self.bp4_label = self.create_label(bid_color) self.bp5_label = self.create_label(bid_color) self.bv1_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight) self.bv2_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight) self.bv3_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight) self.bv4_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight) self.bv5_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight) self.ap1_label = self.create_label(ask_color) self.ap2_label = self.create_label(ask_color) self.ap3_label = self.create_label(ask_color) self.ap4_label = self.create_label(ask_color) self.ap5_label = self.create_label(ask_color) self.av1_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight) self.av2_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight) self.av3_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight) self.av4_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight) self.av5_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight) self.lp_label = self.create_label() self.return_label = self.create_label(alignment=QtCore.Qt.AlignRight) min_width = 70 self.lp_label.setMinimumWidth(min_width) self.return_label.setMinimumWidth(min_width) form2 = QtWidgets.QFormLayout() form2.addRow(self.ap5_label, self.av5_label) form2.addRow(self.ap4_label, self.av4_label) form2.addRow(self.ap3_label, self.av3_label) form2.addRow(self.ap2_label, self.av2_label) form2.addRow(self.ap1_label, self.av1_label) form2.addRow(self.lp_label, self.return_label) form2.addRow(self.bp1_label, self.bv1_label) form2.addRow(self.bp2_label, self.bv2_label) form2.addRow(self.bp3_label, self.bv3_label) form2.addRow(self.bp4_label, self.bv4_label) form2.addRow(self.bp5_label, self.bv5_label) # Set layout hbox = QtWidgets.QHBoxLayout() hbox.addLayout(form1) hbox.addLayout(form2) self.setLayout(hbox)
EVENT_TIMER ) from vnpy.trader.constant import Direction, Offset, OrderType, Interval, Status,Exchange from vnpy.trader.constant import Interval, Exchange from vnpy.chart.manager import BarManager from vnpy.chart.base import ( GREY_COLOR, WHITE_COLOR, CURSOR_COLOR, BLACK_COLOR, to_int, NORMAL_FONT ) from vnpy.chart.axis import DatetimeAxis from vnpy.chart.item import ChartItem from vnpy.trader.database import database_manager from vnpy.trader.jqdata import readCTP from PyQt5.QtCore import QTimer COLOR_LONG = QtGui.QColor("red") COLOR_SHORT = QtGui.QColor("green") COLOR_BID = QtGui.QColor(255, 174, 201) COLOR_ASK = QtGui.QColor(160, 255, 160) COLOR_BLACK = QtGui.QColor("black") from vnpy.trader.jqdata import jqdata_client # @Time : 2019-09-17 # @Author : 龙文浩 # 绘制k线图 class KLineMonitor(pg.PlotWidget): MIN_BAR_COUNT = 100