diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index e18f4ab0b..ce36e4afa 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -607,8 +607,7 @@ func (s *Strategy) CrossRun( s.hedgerConnectivity = types.NewConnectivity() s.hedgerConnectivity.Bind(s.hedgeSession.UserDataStream) - connGroup := types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity) - s.connectivityGroup = connGroup + s.connectivityGroup = types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity) if s.RecoverTrade { go s.runTradeRecover(ctx) @@ -622,7 +621,7 @@ func (s *Strategy) CrossRun( return case <-time.After(3 * time.Minute): log.Panicf("authentication timeout, exiting...") - case <-connGroup.AllAuthedC(ctx): + case <-s.connectivityGroup.AllAuthedC(ctx): } log.Infof("user data stream authenticated, start placing orders...") @@ -1192,6 +1191,8 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) { return } + s.logger.Infof("%d orders are generated, placing...", len(submitOrders)) + _, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...) if err != nil { s.logger.WithError(err).Errorf("submit order error: %s", err.Error()) diff --git a/pkg/util/tradingutil/cancel.go b/pkg/util/tradingutil/cancel.go index 2c24a71ec..459e8b8e6 100644 --- a/pkg/util/tradingutil/cancel.go +++ b/pkg/util/tradingutil/cancel.go @@ -55,26 +55,39 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, symb } } - if len(openOrders) == 0 { - log.Warnf("empty open orders, unable to call specific cancel all orders api, skip") - return nil - } + if len(openOrders) > 0 { + if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok { + var groupIds = CollectOrderGroupIds(openOrders) + for _, groupId := range groupIds { + if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil { + anyErr = err + } + } - if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok { - var groupIds = CollectOrderGroupIds(openOrders) - for _, groupId := range groupIds { - if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil { - anyErr = err + if anyErr == nil { + return nil } } - if anyErr == nil { - return nil + if anyErr != nil { + return anyErr } } - if anyErr != nil { - return anyErr + // if we have no open order, then use the exchange service query to get the open orders and then cancel them all + if len(openOrders) == 0 { + if len(symbol) == 0 { + log.Warnf("empty open orders, unable to call specific cancel all orders api, skip") + return nil + } + + var err error + openOrders, err = retry.QueryOpenOrdersUntilSuccessful(ctx, exchange, symbol) + if err != nil { + return err + } + + return retry.CancelOrdersUntilSuccessful(ctx, exchange, openOrders...) } return fmt.Errorf("unable to cancel all orders, openOrders:%+v", openOrders)