mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
Add validation for support strategy
This commit is contained in:
parent
53133851cc
commit
6718aace8c
|
@ -44,6 +44,18 @@ func (s *Strategy) ID() string {
|
|||
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) {
|
||||
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
|
||||
}
|
||||
|
||||
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%
|
||||
market, ok := session.Market(s.Symbol)
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue
Block a user