[增强] 增加界面联动
行情->交易界面更新 持仓->交易界面更新
This commit is contained in:
parent
d70e0ea304
commit
c5f71910d5
@ -45,6 +45,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.connect_dialogs = {}
|
self.connect_dialogs = {}
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
|
||||||
|
self.trading_widget = None
|
||||||
|
self.position_widget = None
|
||||||
|
self.tick_widget = None
|
||||||
|
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
@ -55,12 +59,18 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.init_menu()
|
self.init_menu()
|
||||||
self.load_window_setting("custom")
|
self.load_window_setting("custom")
|
||||||
|
|
||||||
|
# 绑定行情双击 ~ 交易界面自动填写
|
||||||
|
if self.tick_widget and self.trading_widget:
|
||||||
|
self.tick_widget.itemDoubleClicked.connect(self.trading_widget.auto_fill_symbol)
|
||||||
|
if self.position_widget and self.trading_widget:
|
||||||
|
self.position_widget.itemDoubleClicked.connect(self.trading_widget.close_position)
|
||||||
|
|
||||||
def init_dock(self):
|
def init_dock(self):
|
||||||
""""""
|
""""""
|
||||||
self.trading_widget, trading_dock = self.create_dock(
|
self.trading_widget, trading_dock = self.create_dock(
|
||||||
TradingWidget, "交易", QtCore.Qt.LeftDockWidgetArea
|
TradingWidget, "交易", QtCore.Qt.LeftDockWidgetArea
|
||||||
)
|
)
|
||||||
tick_widget, tick_dock = self.create_dock(
|
self.tick_widget, tick_dock = self.create_dock(
|
||||||
TickMonitor, "行情", QtCore.Qt.RightDockWidgetArea
|
TickMonitor, "行情", QtCore.Qt.RightDockWidgetArea
|
||||||
)
|
)
|
||||||
order_widget, order_dock = self.create_dock(
|
order_widget, order_dock = self.create_dock(
|
||||||
@ -78,7 +88,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
account_widget, account_dock = self.create_dock(
|
account_widget, account_dock = self.create_dock(
|
||||||
AccountMonitor, "资金", QtCore.Qt.BottomDockWidgetArea
|
AccountMonitor, "资金", QtCore.Qt.BottomDockWidgetArea
|
||||||
)
|
)
|
||||||
position_widget, position_dock = self.create_dock(
|
self.position_widget, position_dock = self.create_dock(
|
||||||
PositionMonitor, "持仓", QtCore.Qt.BottomDockWidgetArea
|
PositionMonitor, "持仓", QtCore.Qt.BottomDockWidgetArea
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -631,6 +631,8 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
cancel_button = QtWidgets.QPushButton("全撤")
|
cancel_button = QtWidgets.QPushButton("全撤")
|
||||||
cancel_button.clicked.connect(self.cancel_all)
|
cancel_button.clicked.connect(self.cancel_all)
|
||||||
|
|
||||||
|
self.checkFixed = QtWidgets.QCheckBox("价格") # 价格固定选择框
|
||||||
|
|
||||||
form1 = QtWidgets.QFormLayout()
|
form1 = QtWidgets.QFormLayout()
|
||||||
form1.addRow("交易所", self.exchange_combo)
|
form1.addRow("交易所", self.exchange_combo)
|
||||||
form1.addRow("代码", self.symbol_line)
|
form1.addRow("代码", self.symbol_line)
|
||||||
@ -638,7 +640,7 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
form1.addRow("方向", self.direction_combo)
|
form1.addRow("方向", self.direction_combo)
|
||||||
form1.addRow("开平", self.offset_combo)
|
form1.addRow("开平", self.offset_combo)
|
||||||
form1.addRow("类型", self.order_type_combo)
|
form1.addRow("类型", self.order_type_combo)
|
||||||
form1.addRow("价格", self.price_line)
|
form1.addRow( self.checkFixed, self.price_line)
|
||||||
form1.addRow("数量", self.volume_line)
|
form1.addRow("数量", self.volume_line)
|
||||||
form1.addRow("接口", self.gateway_combo)
|
form1.addRow("接口", self.gateway_combo)
|
||||||
form1.addRow(send_button)
|
form1.addRow(send_button)
|
||||||
@ -725,6 +727,9 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
if tick.vt_symbol != self.vt_symbol:
|
if tick.vt_symbol != self.vt_symbol:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.checkFixed.isChecked():
|
||||||
|
self.price_line.setText(str(tick.last_price))
|
||||||
|
|
||||||
self.lp_label.setText(str(tick.last_price))
|
self.lp_label.setText(str(tick.last_price))
|
||||||
self.bp1_label.setText(str(tick.bid_price_1))
|
self.bp1_label.setText(str(tick.bid_price_1))
|
||||||
self.bv1_label.setText(str(tick.bid_volume_1))
|
self.bv1_label.setText(str(tick.bid_volume_1))
|
||||||
@ -869,6 +874,64 @@ class TradingWidget(QtWidgets.QWidget):
|
|||||||
req = order.create_cancel_request()
|
req = order.create_cancel_request()
|
||||||
self.main_engine.cancel_order(req, order.gateway_name)
|
self.main_engine.cancel_order(req, order.gateway_name)
|
||||||
|
|
||||||
|
def auto_fill_symbol(self, cell):
|
||||||
|
"""根据行情信息自动填写交易组件"""
|
||||||
|
try:
|
||||||
|
# 读取行情数据,cell是一个表格中的单元格对象
|
||||||
|
tick = cell.get_data()
|
||||||
|
if tick is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if tick.symbol:
|
||||||
|
self.symbol_line.setText(tick.symbol)
|
||||||
|
|
||||||
|
if tick.exchange:
|
||||||
|
self.exchange_combo.setCurrentText(tick.exchange.value)
|
||||||
|
|
||||||
|
# 自动填写gateway信息
|
||||||
|
if tick.gateway_name:
|
||||||
|
self.gateway_combo.setCurrentText(tick.gateway_name)
|
||||||
|
|
||||||
|
self.volume_line.setText(str(1))
|
||||||
|
|
||||||
|
self.set_vt_symbol()
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
self.main_engine.write_log(u'tradingWg.autoFillSymbol exception:{}'.format(str(ex)))
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def close_position(self, cell):
|
||||||
|
"""根据持仓信息自动填写交易组件"""
|
||||||
|
try:
|
||||||
|
# 读取持仓数据,cell是一个表格中的单元格对象
|
||||||
|
pos = cell.get_data()
|
||||||
|
if pos is None:
|
||||||
|
return
|
||||||
|
if pos.symbol:
|
||||||
|
self.symbol_line.setText(pos.symbol)
|
||||||
|
|
||||||
|
if pos.exchange:
|
||||||
|
self.exchange_combo.setCurrentText(pos.exchange.value)
|
||||||
|
|
||||||
|
if pos.gateway_name:
|
||||||
|
self.gateway_combo.setCurrentText(pos.gateway_name)
|
||||||
|
|
||||||
|
self.set_vt_symbol()
|
||||||
|
|
||||||
|
self.order_type_combo.setCurrentText(OrderType.LIMIT.value)
|
||||||
|
|
||||||
|
self.offset_combo.setCurrentText(Offset.CLOSE.value)
|
||||||
|
|
||||||
|
self.volume_line.setText(str(pos.volume))
|
||||||
|
|
||||||
|
if pos.direction in [Direction.LONG, Direction.NET]:
|
||||||
|
self.direction_combo.setCurrentText(Direction.SHORT)
|
||||||
|
else:
|
||||||
|
self.direction_combo.setCurrentText(Direction.LONG)
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
self.main_engine.write_log(u'tradingWg.closePosition exception:{}'.format(str(ex)))
|
||||||
|
|
||||||
class ActiveOrderMonitor(OrderMonitor):
|
class ActiveOrderMonitor(OrderMonitor):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user