bbgo: add debug ewma and sma

This commit is contained in:
c9s 2021-10-18 17:26:03 +08:00
parent 30b82390b7
commit d763a3c415
2 changed files with 13 additions and 9 deletions

View File

@ -19,17 +19,12 @@ import (
var (
debugEWMA = false
debugSMA = false
debugSMA = false
)
func init() {
if v, ok := util.GetEnvVarBool("DEBUG_EWMA"); ok {
debugEWMA = v
}
if v, ok := util.GetEnvVarBool("DEBUG_SMA"); ok {
debugSMA = v
}
util.SetEnvVarBool("DEBUG_EWMA", &debugEWMA)
util.SetEnvVarBool("DEBUG_SMA", &debugSMA)
}
type StandardIndicatorSet struct {
@ -69,7 +64,7 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd
set.ewma[iw] = &indicator.EWMA{IntervalWindow: iw}
set.ewma[iw].Bind(store)
// if debug ewma is enabled, we add the debug handler
// if debug EWMA is enabled, we add the debug handler
if debugEWMA {
set.ewma[iw].OnUpdate(func(value float64) {
log.Infof("%s EWMA %s: %f", symbol, iw.String(), value)

View File

@ -38,6 +38,15 @@ func GetEnvVarInt(n string) (int, bool) {
return num, true
}
func SetEnvVarBool(n string, v *bool) bool {
b, ok := GetEnvVarBool(n)
if ok {
*v = b
}
return ok
}
func GetEnvVarBool(n string) (bool, bool) {
str, ok := os.LookupEnv(n)
if !ok {