VeighNa量化社区
你的开源社区量化交易平台
Member
加入于:
帖子: 21
声望: 0

麻烦大佬帮忙看一下热键的问题,想send order直接用热键,不点鼠标。不知道为什么报错。

在vnpy/trader/ui/widget的
class TradingWidget(QtWidgets.QWidget):
def send_order(self) -> None:
下面加了
keyboard.add_hotkey('z+x', send_order, suppress = False)

报错:
Traceback (most recent call last):
File "C:\veighna_studio\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\veighna_studio\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\veighna_studio\lib\site-packages\keyboard_generic.py", line 58, in process
if self.pre_process_event(event):
File "C:\veighna_studio\lib\site-packages\keyboard__init.py", line 218, in pre_process_event
callback(event)
File "C:\veighna_studio\lib\site-packages\keyboard\
init__.py", line 649, in <lambda>
handler = lambda e: (event_type == KEY_DOWN and e.event_type == KEY_UP and e.scan_code in _logically_pressed_keys) or (event_type == e.event_type and callback())
TypeError: TradingWidget.send_order() missing 1 required positional argument: 'self'

Member
avatar
加入于:
帖子: 4556
声望: 277

send_order要传参的,你没传TradingWidget实例self吧

Member
加入于:
帖子: 21
声望: 0

xiaohe wrote:

send_order要传参的,你没传TradingWidget实例self吧

多谢大神。实在不好意思我太菜了,我修改了一下:
def send_order(self) -> None:
...
self.send_order()
tw = TradingWidget()
send_order = tw.send_order()
keyboard.add_hotkey('alt + 7', send_order, suppress = False)

现在的错误是: TypeError: TradingWidget.init() missing 2 required positional arguments: 'main_engine' and 'event_engine'
麻烦再帮忙看一下怎么回事,太感谢了!

Member
avatar
加入于:
帖子: 4556
声望: 277

不是新建实例,你应该传前面用到的实例

Member
加入于:
帖子: 21
声望: 0

xiaohe wrote:

不是新建实例,你应该传前面用到的实例
多谢哦!已经搞定了!谢谢

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

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】