From 30b82390b72fdb30d74bdb76d2e213123bc32612 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 18 Oct 2021 15:23:22 +0800 Subject: [PATCH] bbgo: add EMA and SMA debug var --- pkg/bbgo/session.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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,