diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 28dde0584..fce711e46 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -17,6 +17,21 @@ import ( "github.com/c9s/bbgo/pkg/util" ) +var ( + debugEWMA = 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 + } +} + type StandardIndicatorSet struct { Symbol string // Standard indicators @@ -45,9 +60,22 @@ func NewStandardIndicatorSet(symbol string, store *MarketDataStore) *StandardInd iw := types.IntervalWindow{Interval: interval, Window: window} set.sma[iw] = &indicator.SMA{IntervalWindow: iw} set.sma[iw].Bind(store) + if debugSMA { + set.sma[iw].OnUpdate(func(value float64) { + log.Infof("%s SMA %s: %f", symbol, iw.String(), value) + }) + } set.ewma[iw] = &indicator.EWMA{IntervalWindow: iw} set.ewma[iw].Bind(store) + + // 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) + }) + } + } // setup boll indicator, we may refactor boll indicator by subscribing SMA indicator,