Validate config

This commit is contained in:
なるみ 2021-12-22 01:50:27 +08:00
parent 41d4001872
commit 2999e41ef0

View File

@ -2,6 +2,7 @@ package kline
import (
"context"
"fmt"
"time"
"github.com/sirupsen/logrus"
@ -67,6 +68,32 @@ func (s *Strategy) ID() string {
return ID
}
func (s *Strategy) Validate() error {
if s.Interval == 0 {
return fmt.Errorf("interval shoud not be 0")
}
if len(s.TargetWeights) == 0 {
return fmt.Errorf("targetWeights should not be empty")
}
for currency, weight := range s.TargetWeights {
if weight.Float64() < 0 {
return fmt.Errorf("%s weight: %f should not less than 0", currency, weight.Float64())
}
}
if s.Threshold < 0 {
return fmt.Errorf("threshold should not less than 0")
}
if s.MaxAmount < 0 {
return fmt.Errorf("maxAmount shoud not less than 0")
}
return nil
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {