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 ( var (
debugEWMA = false debugEWMA = false
debugSMA = false debugSMA = false
) )
func init() { func init() {
if v, ok := util.GetEnvVarBool("DEBUG_EWMA"); ok { util.SetEnvVarBool("DEBUG_EWMA", &debugEWMA)
debugEWMA = v util.SetEnvVarBool("DEBUG_SMA", &debugSMA)
}
if v, ok := util.GetEnvVarBool("DEBUG_SMA"); ok {
debugSMA = v
}
} }
type StandardIndicatorSet struct { type StandardIndicatorSet struct {
@ -69,7 +64,7 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd
set.ewma[iw] = &indicator.EWMA{IntervalWindow: iw} set.ewma[iw] = &indicator.EWMA{IntervalWindow: iw}
set.ewma[iw].Bind(store) 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 { if debugEWMA {
set.ewma[iw].OnUpdate(func(value float64) { set.ewma[iw].OnUpdate(func(value float64) {
log.Infof("%s EWMA %s: %f", symbol, iw.String(), value) 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 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) { func GetEnvVarBool(n string) (bool, bool) {
str, ok := os.LookupEnv(n) str, ok := os.LookupEnv(n)
if !ok { if !ok {