From f6128b9bdc044b88a165c0cd276994af2f62c54b Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 21 Jun 2023 15:59:15 +0800 Subject: [PATCH] xalign: support percentage string --- pkg/strategy/xalign/strategy.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index fac24476e..5f19ca938 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -40,7 +40,7 @@ type Strategy struct { ExpectedBalances map[string]fixedpoint.Value `json:"expectedBalances"` UseTakerOrder bool `json:"useTakerOrder"` DryRun bool `json:"dryRun"` - BalanceToleranceRange float64 `json:"balanceToleranceRange"` + BalanceToleranceRange fixedpoint.Value `json:"balanceToleranceRange"` Duration types.Duration `json:"for"` faultBalanceRecords map[string][]TimeBalance @@ -74,7 +74,7 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) { } func (s *Strategy) Defaults() error { - s.BalanceToleranceRange = 0.01 + s.BalanceToleranceRange = fixedpoint.NewFromFloat(0.01) return nil } @@ -292,7 +292,8 @@ func (s *Strategy) recordBalance(totalBalances types.BalanceMap) { for currency, expectedBalance := range s.ExpectedBalances { q := s.calculateRefillQuantity(totalBalances, currency, expectedBalance) rf := q.Div(expectedBalance).Abs().Float64() - if rf > s.BalanceToleranceRange { + tr := s.BalanceToleranceRange.Float64() + if rf > tr { balance := totalBalances[currency] s.faultBalanceRecords[currency] = append(s.faultBalanceRecords[currency], TimeBalance{ Time: now,