xfunding: cancel open orders before closing the futures position

This commit is contained in:
c9s 2023-03-29 22:54:54 +08:00
parent 0c9e0649c6
commit 7e2688b8c7
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -416,6 +416,17 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
s.futuresSession.UserDataStream.OnStart(func() {
if s.CloseFuturesPosition {
openOrders, err := s.futuresSession.Exchange.QueryOpenOrders(ctx, s.Symbol)
if err != nil {
log.WithError(err).Errorf("query open orders error")
} else {
// canceling open orders
if err = s.futuresSession.Exchange.CancelOrders(ctx, openOrders...); err != nil {
log.WithError(err).Errorf("query open orders error")
}
}
if err := s.futuresOrderExecutor.ClosePosition(ctx, fixedpoint.One); err != nil {
log.WithError(err).Errorf("close position error")
}