vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 2
声望: 0

自定义了一个用户UI界面,用来显示行情,仓位信息,主要代码如下:

信号定义

signal_position: QtCore.pyqtSignal = QtCore.pyqtSignal(Event)
signal_price: QtCore.pyqtSignal = QtCore.pyqtSignal(Event)
signal_strategy_data: QtCore.pyqtSignal = QtCore.pyqtSignal(Event)
signal_log: QtCore.pyqtSignal = QtCore.pyqtSignal(Event)

信号注册

def register_event(self):
    """
    Register event handler into event engine.
    """
    # 持仓响应
    self.signal_position.connect(self.postion_process_event)
    self.event_engine.register(EVENT_POSITION, self.signal_position.emit)
    # 价格响应
    self.signal_price.connect(self.price_process_event)
    self.event_engine.register(EVENT_TICK, self.signal_price.emit)
    # 策略数据响应
    self.signal_strategy_data.connect(self.strategy_data_process_event)
    self.event_engine.register(EVENT_CTA_STRATEGY, self.signal_strategy_data.emit)
    # 注册日志数据反显响应函数
    self.signal_log.connect(self.log_process_event)
    self.event_engine.register(EVENT_LOG, self.signal_log.emit)

运行一段时间后会提示如下错误:
Traceback (most recent call last):
File "C:\vnstudio\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\vnstudio\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 60, in _run
self._process(event)
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 74, in _process
[handler(event) for handler in self._handlers[event.type]]
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 74, in <listcomp>
[handler(event) for handler in self._handlers[event.type]]
AttributeError: 'main_window' does not have a signal with the signature signal_position(PyQt_PyObject)

不知道是什么原因

Administrator
avatar
加入于:
帖子: 4871
声望: 283

你的MainWindow对象,没有定义signal_position这个信号对象

Member
avatar
加入于:
帖子: 2
声望: 0

用Python的交易员 wrote:

你的MainWindow对象,没有定义signal_position这个信号对象
谢谢回复~
mainwindow这个类初始化就定义好了signal_position这个对象,而且是可以运行的,就是会偶尔跳出这个异常,尤其是删除或者增加策略后,界面发生了变化,这个异常出现的概率更大。
有时候提示的异常是找不到其他的signal对象,比如signal_price,signal_log,就有点奇怪。

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号