From 18e9c95e3970aafb80e3bf9d22e0944c28370b00 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 8 May 2026 17:10:58 +0800 Subject: [PATCH] add maintenance sync check --- pkg/bbgo/environment.go | 17 ++++++++++++++++- pkg/strategy/xalign/strategy.go | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index e22c4e48b8..1435f31733 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -296,7 +296,7 @@ func (environ *Environment) ConfigureExchangeSessions(userConfig *Config) error } func (environ *Environment) AddExchangesByViperKeys() error { - for n, _ := range types.SupportedExchanges { + for n := range types.SupportedExchanges { if viper.IsSet(string(n) + "-api-key") { exMinimal, err := exchange.NewWithEnvVarPrefix(n, "") if err != nil { @@ -520,6 +520,11 @@ func (environ *Environment) syncWithUserConfig(ctx context.Context, userConfig * } } for _, session := range sessions { + if session.IsInMaintenance() { + log.Infof("session %s is in maintenance mode, skipping sync", session.Name) + continue + } + var syncSymbols []string // if there are session specific symbols defined, we use those. // Otherwise we use the rest symbols that are not categorized into any session. @@ -583,6 +588,11 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err // the default sync logics since := defaultSyncSinceTime() for _, session := range environ.sessions { + if session.IsInMaintenance() { + log.Infof("session %s is in maintenance mode, skipping sync", session.Name) + continue + } + if err := environ.syncSession(ctx, session, since); err != nil { return err } @@ -652,6 +662,11 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types } func (environ *Environment) SyncSession(ctx context.Context, session *ExchangeSession, defaultSymbols ...string) error { + if session.IsInMaintenance() { + log.Infof("session %s is in maintenance mode, skipping SyncSession", session.Name) + return nil + } + if environ.SyncService == nil { return nil } diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index bb4c226215..62247e496b 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -243,6 +243,11 @@ func (s *Strategy) selectSessionForCurrency( continue } + if session.IsInMaintenance() { + log.Infof("session %s is in maintenance, skipping", sessionName) + continue + } + account, err := session.UpdateAccount(ctx) if err != nil { log.WithError(err).Errorf("unable to update account for session %s", sessionName) @@ -628,12 +633,33 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap) } } + anyMaintenance := false + for _, session := range sessions { + if session.IsInMaintenance() { + anyMaintenance = true + break + } + } + totalBalances, _, err := sessions.AggregateBalances(ctx, false) if err != nil { log.WithError(err).Errorf("unable to aggregate balances") return activeTransferExists } + balanceQueryAvailable := true + for _, session := range sessions { + if session.IsInMaintenance() && session.Maintenance != nil && !session.Maintenance.BalanceQueryAvailable { + balanceQueryAvailable = false + break + } + } + + if anyMaintenance && !balanceQueryAvailable { + log.Warn("one of the sessions is in maintenance and balance query is not available, skipping align") + return activeTransferExists + } + s.recordBalances(totalBalances, time.Now()) log.Debugf("checking all fault balance records...")