` def on_trade(self, trade: TradeData):
"""
Callback of new trade data update.
"""
msg = ["trade >>> ", trade.datetime, trade.symbol, trade.orderid, trade.tradeid, trade.direction, trade.offset, trade.price, trade.volume]
self.write_log("\t".join([str(x) for x in msg]))
self.write_log(self.bullorder)
self.write_log(self.bearorder)
# 处理开多
if trade.direction.value == Direction.LONG.value and trade.offset.value == "开":
self.bullorder["status"] = "POS"
self.bullorder["trade_time"] = trade.datetime
# 多单止盈
self.write_log("=========================================bull止盈================================================")
self.sell(self.bullorder["takeprofit_price"], 1)
# 多单止损
self.write_log("=========================================bull止损================================================")
self.sell(self.bullorder["stoploss_price"], 1)`
如代码, 在on_trade中挂止盈止损, 但是只有前面的止盈可以委托成功, 止损并未发出, 为啥?
然后再高频中应该怎样现价止损?