fix order waiting for graceful shutdown

This commit is contained in:
c9s 2021-05-09 19:44:51 +08:00
parent e06310da26
commit 74e01ce444

View File

@ -493,7 +493,6 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
position := s.state.HedgePosition.AtomicLoad() position := s.state.HedgePosition.AtomicLoad()
abspos := math.Abs(position.Float64()) abspos := math.Abs(position.Float64())
if !s.DisableHedge && abspos > s.sourceMarket.MinQuantity { if !s.DisableHedge && abspos > s.sourceMarket.MinQuantity {
log.Infof("found position: %f", position.Float64())
s.Hedge(ctx, -position) s.Hedge(ctx, -position)
} }
} }
@ -512,14 +511,16 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
} }
for { for {
log.Warnf("waiting for orders to be cancelled...")
time.Sleep(1 * time.Second)
orders := s.activeMakerOrders.Orders() orders := s.activeMakerOrders.Orders()
if len(orders) == 0 { if len(orders) == 0 {
log.Info("all orders are cancelled successfully") log.Info("all orders are cancelled successfully")
break break
} }
log.Warnf("waiting for %d orders to be cancelled...", len(orders)) log.Warnf("%d orders are not cancelled yet...", len(orders))
time.Sleep(1 * time.Second)
} }
if err := s.Persistence.Save(s.state, ID, s.Symbol, stateKey); err != nil { if err := s.Persistence.Save(s.state, ID, s.Symbol, stateKey); err != nil {