mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Add a validator interface to validate strategy before run
This commit is contained in:
parent
74d313305c
commit
dbf5d27f30
|
@ -35,6 +35,10 @@ type CrossExchangeStrategy interface {
|
|||
CrossRun(ctx context.Context, orderExecutionRouter OrderExecutionRouter, sessions map[string]*ExchangeSession) error
|
||||
}
|
||||
|
||||
type Validator interface {
|
||||
Validate() error
|
||||
}
|
||||
|
||||
//go:generate callbackgen -type Graceful
|
||||
type Graceful struct {
|
||||
shutdownCallbacks []func(ctx context.Context, wg *sync.WaitGroup)
|
||||
|
@ -235,6 +239,13 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si
|
|||
}
|
||||
}
|
||||
|
||||
// If the strategy has Validate() method, run it and check the error
|
||||
if v, ok := strategy.(Validator); ok {
|
||||
if err := v.Validate(); err != nil {
|
||||
return fmt.Errorf("failed to validate the config: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return strategy.Run(ctx, orderExecutor, session)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user