Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/bbgo/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/strategy/xalign/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...")
Expand Down
Loading