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

问题1、实盘中cta策略的on_trade里打印成交信息,只能打出开仓,不能打出平仓的。
jupyter回测的时候又能正常打印,代码如下:

    def on_trade(self, trade: TradeData):
        """
        Callback of new trade data update.
        """
        if trade.offset == Offset.OPEN:
            print(self.nowtime(),"开--仓成交回报:","交易方向:",trade.direction,"开平:",trade.offset,"持仓:",self.pos,"成交价格:",trade.price)
        elif trade.offset == Offset.CLOSE or trade.offset == Offset.CLOSETODAY or trade.offset == Offset.CLOSEYESTERDAY:
            print(self.nowtime(),"平--仓成交回报:"," 交易方向:",trade.direction,"开平:",trade.offset,"持仓:",self.pos,"成交价格:",trade.price)

        self.put_event()

问题2:on_order里的内容会打印两次一样的

    def on_order(self, order: OrderData):
        """
        Callback of new order data update.
        """
        print(self.nowtime(),"收到on_order委托单......")
Administrator
avatar
加入于:
帖子: 3913
声望: 209
  1. elif改为else试试
  2. order第一次状态是submitting,然后是not traded,然后再到成交
Member
加入于:
帖子: 19
声望: 0

用Python的交易员 wrote:

  1. elif改为else试试
  2. order第一次状态是submitting,然后是not traded,然后再到成交
    非常感谢,已正常
© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3