Merge pull request #1451 from c9s/feature/xdepthmaker

CHORE: [xdepthmaker] improve shutdown process
This commit is contained in:
c9s 2023-12-13 16:47:01 +08:00 committed by GitHub
commit 6dd3766776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -199,14 +199,23 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
// since ctx might be canceled, we should use background context here
if err := ex.CancelOrders(context.Background(), orders...); err != nil {
log.WithError(err).Errorf("[ActiveOrderBook] can not cancel %s orders", b.Symbol)
log.WithError(err).Warnf("[ActiveOrderBook] can not cancel %s orders", b.Symbol)
}
log.Debugf("[ActiveOrderBook] waiting %s for %s orders to be cancelled...", waitTime, b.Symbol)
if cancelAll {
clear, err := b.waitAllClear(ctx, waitTime, orderCancelTimeout)
if clear || err != nil {
if err != nil {
if !errors.Is(err, context.Canceled) {
log.WithError(err).Errorf("order cancel error")
}
break
}
if clear {
log.Debugf("[ActiveOrderBook] %s orders are canceled", b.Symbol)
break
}
@ -216,6 +225,7 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
} else {
existingOrders := b.filterExistingOrders(orders)
if len(existingOrders) == 0 {
log.Debugf("[ActiveOrderBook] orders are canceled")
break
}
}

View File

@ -474,14 +474,11 @@ func (s *Strategy) CrossRun(
// wait for the quoter to stop
time.Sleep(s.UpdateInterval.Duration())
shutdownCtx, cancelShutdown := context.WithTimeout(context.TODO(), time.Minute)
defer cancelShutdown()
if err := s.MakerOrderExecutor.GracefulCancel(shutdownCtx); err != nil {
if err := s.MakerOrderExecutor.GracefulCancel(ctx); err != nil {
log.WithError(err).Errorf("graceful cancel %s order error", s.Symbol)
}
if err := s.HedgeOrderExecutor.GracefulCancel(shutdownCtx); err != nil {
if err := s.HedgeOrderExecutor.GracefulCancel(ctx); err != nil {
log.WithError(err).Errorf("graceful cancel %s order error", s.Symbol)
}
@ -890,6 +887,13 @@ func (s *Strategy) cleanUpOpenOrders(ctx context.Context) error {
return err
}
if len(openOrders) == 0 {
return nil
}
log.Infof("found existing open orders:")
types.OrderSlice(openOrders).Print()
if err := s.makerSession.Exchange.CancelOrders(ctx, openOrders...); err != nil {
return err
}