mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #719 from andycheng123/improve/optimizer
optimizer: bool type parameter
This commit is contained in:
commit
694c226bc0
|
@ -115,6 +115,35 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
|||
return nil
|
||||
}
|
||||
ops = append(ops, f)
|
||||
case "bool":
|
||||
values := []bool{true, false}
|
||||
f := func(configJson []byte, next func(configJson []byte) error) error {
|
||||
for _, val := range values {
|
||||
log.Debugf("%d %s: %v of %v", ii, path, val, values)
|
||||
|
||||
jsonOp := []byte(reformatJson(fmt.Sprintf(`[{"op": "replace", "path": "%s", "value": %v}]`, path, val)))
|
||||
patch, err := jsonpatch.DecodePatch(jsonOp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("json op: %s", jsonOp)
|
||||
|
||||
patchedJson, err := patch.ApplyIndent(configJson, " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
valCopy := val
|
||||
o.CurrentParams[ii] = valCopy
|
||||
if err := next(patchedJson); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
ops = append(ops, f)
|
||||
}
|
||||
}
|
||||
return ops
|
||||
|
|
Loading…
Reference in New Issue
Block a user