optimizer: prepare database before executing backtests

This commit is contained in:
Raphanus Lo 2022-07-13 15:28:11 +08:00
parent 7daa73917c
commit 4985c760be
2 changed files with 18 additions and 0 deletions

View File

@ -101,6 +101,10 @@ var optimizeCmd = &cobra.Command{
Config: optConfig,
}
if err := executor.Prepare(configJson); err != nil {
return err
}
metrics, err := optz.Run(executor, configJson)
if err != nil {
return err

View File

@ -76,6 +76,20 @@ func (e *LocalProcessExecutor) readReport(output []byte) (*backtest.SummaryRepor
return summaryReport, nil
}
// Prepare prepares the environment for the following back tests
// this is a blocking operation
func (e *LocalProcessExecutor) Prepare(configJson []byte) error {
log.Debugln("Sync database before launching backtests...")
tf, err := jsonToYamlConfig(e.ConfigDir, configJson)
if err != nil {
return err
}
c := exec.Command(e.Bin, "backtest", "--sync", "--sync-only", "--config", tf.Name())
_, err = c.Output()
return err
}
func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask, bar *pb.ProgressBar) (chan BacktestTask, error) {
var maxNumOfProcess = e.Config.MaxNumberOfProcesses
var resultsC = make(chan BacktestTask, maxNumOfProcess*2)