xalign: support percentage string

This commit is contained in:
c9s 2023-06-21 15:59:15 +08:00
parent 76884a4ddf
commit f6128b9bdc
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -40,7 +40,7 @@ type Strategy struct {
ExpectedBalances map[string]fixedpoint.Value `json:"expectedBalances"` ExpectedBalances map[string]fixedpoint.Value `json:"expectedBalances"`
UseTakerOrder bool `json:"useTakerOrder"` UseTakerOrder bool `json:"useTakerOrder"`
DryRun bool `json:"dryRun"` DryRun bool `json:"dryRun"`
BalanceToleranceRange float64 `json:"balanceToleranceRange"` BalanceToleranceRange fixedpoint.Value `json:"balanceToleranceRange"`
Duration types.Duration `json:"for"` Duration types.Duration `json:"for"`
faultBalanceRecords map[string][]TimeBalance faultBalanceRecords map[string][]TimeBalance
@ -74,7 +74,7 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
} }
func (s *Strategy) Defaults() error { func (s *Strategy) Defaults() error {
s.BalanceToleranceRange = 0.01 s.BalanceToleranceRange = fixedpoint.NewFromFloat(0.01)
return nil return nil
} }
@ -292,7 +292,8 @@ func (s *Strategy) recordBalance(totalBalances types.BalanceMap) {
for currency, expectedBalance := range s.ExpectedBalances { for currency, expectedBalance := range s.ExpectedBalances {
q := s.calculateRefillQuantity(totalBalances, currency, expectedBalance) q := s.calculateRefillQuantity(totalBalances, currency, expectedBalance)
rf := q.Div(expectedBalance).Abs().Float64() rf := q.Div(expectedBalance).Abs().Float64()
if rf > s.BalanceToleranceRange { tr := s.BalanceToleranceRange.Float64()
if rf > tr {
balance := totalBalances[currency] balance := totalBalances[currency]
s.faultBalanceRecords[currency] = append(s.faultBalanceRecords[currency], TimeBalance{ s.faultBalanceRecords[currency] = append(s.faultBalanceRecords[currency], TimeBalance{
Time: now, Time: now,