add environ.DatabaseService nil check for backtest

This commit is contained in:
c9s 2021-03-22 22:48:43 +08:00
parent 3a842836cd
commit 29f77c2176

View File

@ -95,7 +95,6 @@ var BacktestCmd = &cobra.Command{
return err return err
} }
if userConfig.Backtest == nil { if userConfig.Backtest == nil {
return errors.New("backtest config is not defined") return errors.New("backtest config is not defined")
} }
@ -111,10 +110,14 @@ var BacktestCmd = &cobra.Command{
} }
environ := bbgo.NewEnvironment() environ := bbgo.NewEnvironment()
if err := environ.ConfigureDatabase(ctx) ; err != nil { if err := environ.ConfigureDatabase(ctx); err != nil {
return err return err
} }
if environ.DatabaseService == nil {
return errors.New("database service is not enabled, please check your environment variables DB_DRIVER and DB_DSN")
}
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB} backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
if wantSync { if wantSync {
@ -277,4 +280,3 @@ var BacktestCmd = &cobra.Command{
return nil return nil
}, },
} }