mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fix graceful shutdown
This commit is contained in:
parent
405f9c863f
commit
dde998aced
|
@ -159,13 +159,12 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config, enableWebServer
|
|||
|
||||
cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
cancelTrading()
|
||||
|
||||
log.Infof("shutting down stratgies...")
|
||||
shutdownCtx, cancelShutdown := context.WithDeadline(ctx, time.Now().Add(30*time.Second))
|
||||
|
||||
log.Infof("shutting down...")
|
||||
trader.Graceful.Shutdown(shutdownCtx)
|
||||
cancelShutdown()
|
||||
cancelTrading()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -487,9 +487,11 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
select {
|
||||
|
||||
case <-s.stopC:
|
||||
log.Warnf("%s maker goroutine stopped, due to the stop signal", s.Symbol)
|
||||
return
|
||||
|
||||
case <-ctx.Done():
|
||||
log.Warnf("%s maker goroutine stopped, due to the cancelled context", s.Symbol)
|
||||
return
|
||||
|
||||
case <-quoteTicker.C:
|
||||
|
@ -510,7 +512,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
|
||||
close(s.stopC)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
time.Sleep(s.UpdateInterval.Duration())
|
||||
|
||||
for {
|
||||
if err := s.makerSession.Exchange.CancelOrders(ctx, s.activeMakerOrders.Orders()...); err != nil {
|
||||
|
@ -534,7 +536,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
log.WithError(err).Errorf("can not save state: %+v", s.state)
|
||||
} else {
|
||||
log.Infof("state is saved => %+v", s.state)
|
||||
s.Notify("%s hedge position %f is saved", s.Symbol, s.state.HedgePosition.Float64())
|
||||
s.Notify("%s position is saved: position = %f", s.Symbol, s.state.HedgePosition.Float64())
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user