vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 9
声望: 0

初始化策略没有问题,启动策略后报错:
1234: 触发异常已停止
Traceback (most recent call last):
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\engine.py", line 446, in call_strategy_func
func(params)
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\strategies\MyTest_strategy.py", line 42, in on_tick
self.buy(tick.last_price + 1, self.fixed_size)
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\template.py", line 142, in buy
return self.send_order(CtaOrderType.BUY, price, volume, stop)
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\template.py", line 174, in send_order
self, order_type, price, volume, stop
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\engine.py", line 370, in send_order
return self.send_limit_order(strategy, order_type, price, volume)
File "D:\ProgramData\VNConda\lib\site-packages\vnpy\app\cta_strategy\engine.py", line 278, in send_limit_order
volume=volume,
TypeError: init() got an unexpected keyword argument 'dierction'

请各位大佬帮忙看看 感激不尽^^
code text here
```

Administrator
avatar
加入于:
帖子: 1408
声望: 63

请在github上开个issue吧,我安排人来查下

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

用Python的交易员 wrote:

请在github上开个issue吧,我安排人来查下
好的 感谢大佬!issue号:1443

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

这个问题我也碰到了,并且已经把'dierction’改成了direction,但是还是报错:
12345: 触发异常已停止

Traceback (most recent call last):

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\engine.py", line 453, in call_strategy_func

func()

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\strategies\dual_thrust_strategy.py", line 77, in on_tick

self.bg.update_tick(tick)

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\trader\utility.py", line 149, in update_tick

self.on_bar(self.bar)

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\strategies\dual_thrust_strategy.py", line 135, in on_bar

self.buy(self.long_entry, self.fixed_size, stop=True)

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\template.py", line 143, in buy

return self.send_order(CtaOrderType.BUY, price, volume, stop)

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\template.py", line 175, in send_order

self, order_type, price, volume, stop

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\engine.py", line 375, in send_order

return self.send_limit_order(strategy, order_type, price, volume)

File "C:\Users\Administrator\Desktop\安装包\vnpy-master\vnpy-master\vnpy\app\cta_strategy\engine.py", line 319, in send_stop_order

TypeError: init() got an unexpected keyword argument 'direction'

无语了。。。后来看了下stopOrder的 init,

@dataclass
class StopOrder:
    vt_symbol: str
    order_type: CtaOrderType
    price: float
    volume: float
    stop_orderid: str
    strategy_name: str
    status: StopOrderStatus = StopOrderStatus.WAITING
    vt_orderid: str = ""

    def __post_init__(self):
        """"""
        self.direction, self.offset = ORDER_CTA2VT[self.order_type]

感觉在实例化的时候

stop_order = StopOrder(
            vt_symbol=strategy.vt_symbol,
            price=price,
            volume=volume,
            stop_orderid=stop_orderid,
            strategy_name=strategy.strategy_name,
            order_type = order_type
        )

这样也应该没有问题。
修改了一下至少没报错,策略下单还在研究

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