From d8150a17b965108076d20c2033bf2303cc46c069 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 5 Nov 2024 15:20:03 +0800 Subject: [PATCH] xalign: move activeTransferNotificationLimiter into the strategy struct --- pkg/strategy/xalign/strategy.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 4bf62f23c..f86d4e11c 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -22,8 +22,6 @@ const ID = "xalign" var log = logrus.WithField("strategy", ID) -var activeTransferNotificationLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1) - func init() { bbgo.RegisterStrategy(ID, &Strategy{}) } @@ -63,6 +61,8 @@ type Strategy struct { orderBooks map[string]*bbgo.ActiveOrderBook orderStore *core.OrderStore + + activeTransferNotificationLimiter *rate.Limiter } func (s *Strategy) ID() string { @@ -92,6 +92,11 @@ func (s *Strategy) Defaults() error { return nil } +func (s *Strategy) Initialize() error { + s.activeTransferNotificationLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1) + return nil +} + func (s *Strategy) Validate() error { if s.PreferredQuoteCurrencies == nil { return errors.New("quoteCurrencies is not defined") @@ -483,7 +488,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange s.resetFaultBalanceRecords(pendingWithdraw.Asset) - if activeTransferNotificationLimiter.Allow() { + if s.activeTransferNotificationLimiter.Allow() { bbgo.Notify("Found active %s withdraw, skip balance align", pendingWithdraw.Asset, pendingWithdraw) @@ -502,7 +507,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange s.resetFaultBalanceRecords(pendingDeposit.Asset) - if activeTransferNotificationLimiter.Allow() { + if s.activeTransferNotificationLimiter.Allow() { bbgo.Notify("Found active %s deposit, skip balance align", pendingDeposit.Asset, pendingDeposit)