From d4cab7bfc2a9ebf2fc45ba76358a18094cc71bf7 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 15 Sep 2019 21:46:49 +0800 Subject: [PATCH] [Add] stop algo by double click monitor cells --- vnpy/app/spread_trading/engine.py | 5 +++-- vnpy/app/spread_trading/template.py | 4 ++-- vnpy/app/spread_trading/ui/widget.py | 25 +++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/vnpy/app/spread_trading/engine.py b/vnpy/app/spread_trading/engine.py index f59739a7..8bcfb831 100644 --- a/vnpy/app/spread_trading/engine.py +++ b/vnpy/app/spread_trading/engine.py @@ -274,7 +274,8 @@ class SpreadAlgoEngine: self.event_engine.register(EVENT_ORDER, self.process_order_event) self.event_engine.register(EVENT_TRADE, self.process_trade_event) self.event_engine.register(EVENT_TIMER, self.process_timer_event) - self.event_engine.register(EVENT_SPREAD_DATA, self.process_spread_event) + self.event_engine.register( + EVENT_SPREAD_DATA, self.process_spread_event) def process_spread_event(self, event: Event): """""" @@ -311,7 +312,7 @@ class SpreadAlgoEngine: def process_timer_event(self, event: Event): """""" - buf = self.algos.values() + buf = list(self.algos.values()) for algo in buf: if not algo.is_active(): diff --git a/vnpy/app/spread_trading/template.py b/vnpy/app/spread_trading/template.py index 8ab76697..6c967d91 100644 --- a/vnpy/app/spread_trading/template.py +++ b/vnpy/app/spread_trading/template.py @@ -103,7 +103,7 @@ class SpreadAlgoTemplate: if self.is_active(): self.cancel_all_order() self.status = Status.CANCELLED - self.put_algo_event() + self.put_event() def update_tick(self, tick: TickData): """""" @@ -138,7 +138,7 @@ class SpreadAlgoTemplate: def put_event(self): """""" - self.algo_engine.put_event(self) + self.algo_engine.put_algo_event(self) def write_log(self, msg: str): """""" diff --git a/vnpy/app/spread_trading/ui/widget.py b/vnpy/app/spread_trading/ui/widget.py index b1b797ad..ebfe8977 100644 --- a/vnpy/app/spread_trading/ui/widget.py +++ b/vnpy/app/spread_trading/ui/widget.py @@ -52,8 +52,7 @@ class SpreadManager(QtWidgets.QWidget): self.event_engine ) self.algo_monitor = SpreadAlgoMonitor( - self.main_engine, - self.event_engine + self.spread_engine ) add_spread_button = QtWidgets.QPushButton("创建价差") @@ -164,6 +163,28 @@ class SpreadAlgoMonitor(BaseMonitor): "status": {"display": "状态", "cell": EnumCell, "update": True}, } + def __init__(self, spread_engine: SpreadEngine): + """""" + super().__init__(spread_engine.main_engine, spread_engine.event_engine) + + self.spread_engine = spread_engine + + def init_ui(self): + """ + Connect signal. + """ + super().init_ui() + + self.setToolTip("双击单元格停止算法") + self.itemDoubleClicked.connect(self.stop_algo) + + def stop_algo(self, cell): + """ + Stop algo if cell double clicked. + """ + algo = cell.get_data() + self.spread_engine.stop_algo(algo.algoid) + class SpreadAlgoDialog(QtWidgets.QDialog): """"""