mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add debug ewma and sma
This commit is contained in:
parent
30b82390b7
commit
d763a3c415
|
@ -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)
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user