Add validation for support strategy

This commit is contained in:
Larry850806 2021-04-02 10:32:24 +08:00
parent 53133851cc
commit 6718aace8c

View File

@ -44,6 +44,18 @@ func (s *Strategy) ID() string {
return ID return ID
} }
func (s *Strategy) Validate() error {
if s.Quantity == 0 && s.ScaleQuantity == nil {
return fmt.Errorf("quantity or scaleQuantity can not be zero")
}
if s.MinVolume == 0 {
return fmt.Errorf("minVolume can not be zero")
}
return nil
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: string(s.Interval)}) session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: string(s.Interval)})
} }
@ -58,14 +70,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.MovingAverageWindow = 99 s.MovingAverageWindow = 99
} }
if s.Quantity == 0 && s.ScaleQuantity == nil {
return fmt.Errorf("quantity or scaleQuantity can not be zero")
}
if s.MinVolume == 0 {
return fmt.Errorf("minVolume can not be zero")
}
// buy when price drops -8% // buy when price drops -8%
market, ok := session.Market(s.Symbol) market, ok := session.Market(s.Symbol)
if !ok { if !ok {