add force parameter for backtest

This commit is contained in:
TonyQ 2021-12-04 16:18:51 +00:00
parent 0a159d96d8
commit bd325f02a5

View File

@ -27,6 +27,7 @@ func init() {
BacktestCmd.Flags().Bool("base-asset-baseline", false, "use base asset performance as the competitive baseline performance") BacktestCmd.Flags().Bool("base-asset-baseline", false, "use base asset performance as the competitive baseline performance")
BacktestCmd.Flags().CountP("verbose", "v", "verbose level") BacktestCmd.Flags().CountP("verbose", "v", "verbose level")
BacktestCmd.Flags().String("config", "config/bbgo.yaml", "strategy config file") BacktestCmd.Flags().String("config", "config/bbgo.yaml", "strategy config file")
BacktestCmd.Flags().Bool("force", false, "force execution without confirm")
RootCmd.AddCommand(BacktestCmd) RootCmd.AddCommand(BacktestCmd)
} }
@ -59,6 +60,11 @@ var BacktestCmd = &cobra.Command{
return err return err
} }
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
syncOnly, err := cmd.Flags().GetBool("sync-only") syncOnly, err := cmd.Flags().GetBool("sync-only")
if err != nil { if err != nil {
return err return err
@ -207,8 +213,11 @@ var BacktestCmd = &cobra.Command{
log.Warn("!!! To run backtest, you should use an isolated database for storing backtest trades !!!") log.Warn("!!! To run backtest, you should use an isolated database for storing backtest trades !!!")
log.Warn("!!! The trade record in the current database WILL ALL BE DELETE !!!") log.Warn("!!! The trade record in the current database WILL ALL BE DELETE !!!")
if !confirmation("Are you sure to continue?") {
return nil if !force {
if !confirmation("Are you sure to continue?") {
return nil
}
} }
if err := environ.TradeService.DeleteAll(); err != nil { if err := environ.TradeService.DeleteAll(); err != nil {