当一个订单下单成功的时候,我怎么知道它时开仓/平仓,方向,仓位的呢?on_trade吗?具体怎么判断呢?
def on_trade(self, trade: TradeData):
"""
Callback of new trade data update.
"""
if self.pos != 0:
if self.pos > 0:
for short_orderid in self.short_vt_orderids:
self.cancel_order(short_orderid)
elif self.pos < 0:
for buy_orderid in self.long_vt_orderids:
self.cancel_order(buy_orderid)
for orderid in (self.long_vt_orderids + self.short_vt_orderids):
if orderid in self.vt_orderids:
self.vt_orderids.remove(orderid)
self.put_event()