Merge pull request #817 from COLDTURNIP/fix/optimizer_initial_storage

optimizer: prepare database before executing backtests
This commit is contained in:
Yo-An Lin 2022-07-13 23:01:59 +08:00 committed by GitHub
commit 01d50496a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

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

View File

@ -76,6 +76,20 @@ func (e *LocalProcessExecutor) readReport(output []byte) (*backtest.SummaryRepor
return summaryReport, nil 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) { func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask, bar *pb.ProgressBar) (chan BacktestTask, error) {
var maxNumOfProcess = e.Config.MaxNumberOfProcesses var maxNumOfProcess = e.Config.MaxNumberOfProcesses
var resultsC = make(chan BacktestTask, maxNumOfProcess*2) var resultsC = make(chan BacktestTask, maxNumOfProcess*2)