mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #1451 from c9s/feature/xdepthmaker
CHORE: [xdepthmaker] improve shutdown process
This commit is contained in:
commit
6dd3766776
|
@ -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
|
// since ctx might be canceled, we should use background context here
|
||||||
if err := ex.CancelOrders(context.Background(), orders...); err != nil {
|
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)
|
log.Debugf("[ActiveOrderBook] waiting %s for %s orders to be cancelled...", waitTime, b.Symbol)
|
||||||
|
|
||||||
if cancelAll {
|
if cancelAll {
|
||||||
clear, err := b.waitAllClear(ctx, waitTime, orderCancelTimeout)
|
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
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +225,7 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
|
||||||
} else {
|
} else {
|
||||||
existingOrders := b.filterExistingOrders(orders)
|
existingOrders := b.filterExistingOrders(orders)
|
||||||
if len(existingOrders) == 0 {
|
if len(existingOrders) == 0 {
|
||||||
|
log.Debugf("[ActiveOrderBook] orders are canceled")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,14 +474,11 @@ func (s *Strategy) CrossRun(
|
||||||
// wait for the quoter to stop
|
// wait for the quoter to stop
|
||||||
time.Sleep(s.UpdateInterval.Duration())
|
time.Sleep(s.UpdateInterval.Duration())
|
||||||
|
|
||||||
shutdownCtx, cancelShutdown := context.WithTimeout(context.TODO(), time.Minute)
|
if err := s.MakerOrderExecutor.GracefulCancel(ctx); err != nil {
|
||||||
defer cancelShutdown()
|
|
||||||
|
|
||||||
if err := s.MakerOrderExecutor.GracefulCancel(shutdownCtx); err != nil {
|
|
||||||
log.WithError(err).Errorf("graceful cancel %s order error", s.Symbol)
|
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)
|
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
|
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 {
|
if err := s.makerSession.Exchange.CancelOrders(ctx, openOrders...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user