问题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委托单......")