xalign: move activeTransferNotificationLimiter into the strategy struct

This commit is contained in:
c9s 2024-11-05 15:20:03 +08:00
parent 822c2bd5e0
commit d8150a17b9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -22,8 +22,6 @@ const ID = "xalign"
var log = logrus.WithField("strategy", ID) var log = logrus.WithField("strategy", ID)
var activeTransferNotificationLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1)
func init() { func init() {
bbgo.RegisterStrategy(ID, &Strategy{}) bbgo.RegisterStrategy(ID, &Strategy{})
} }
@ -63,6 +61,8 @@ type Strategy struct {
orderBooks map[string]*bbgo.ActiveOrderBook orderBooks map[string]*bbgo.ActiveOrderBook
orderStore *core.OrderStore orderStore *core.OrderStore
activeTransferNotificationLimiter *rate.Limiter
} }
func (s *Strategy) ID() string { func (s *Strategy) ID() string {
@ -92,6 +92,11 @@ func (s *Strategy) Defaults() error {
return nil return nil
} }
func (s *Strategy) Initialize() error {
s.activeTransferNotificationLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1)
return nil
}
func (s *Strategy) Validate() error { func (s *Strategy) Validate() error {
if s.PreferredQuoteCurrencies == nil { if s.PreferredQuoteCurrencies == nil {
return errors.New("quoteCurrencies is not defined") 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) s.resetFaultBalanceRecords(pendingWithdraw.Asset)
if activeTransferNotificationLimiter.Allow() { if s.activeTransferNotificationLimiter.Allow() {
bbgo.Notify("Found active %s withdraw, skip balance align", bbgo.Notify("Found active %s withdraw, skip balance align",
pendingWithdraw.Asset, pendingWithdraw.Asset,
pendingWithdraw) pendingWithdraw)
@ -502,7 +507,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
s.resetFaultBalanceRecords(pendingDeposit.Asset) s.resetFaultBalanceRecords(pendingDeposit.Asset)
if activeTransferNotificationLimiter.Allow() { if s.activeTransferNotificationLimiter.Allow() {
bbgo.Notify("Found active %s deposit, skip balance align", bbgo.Notify("Found active %s deposit, skip balance align",
pendingDeposit.Asset, pendingDeposit.Asset,
pendingDeposit) pendingDeposit)