From b2538b69600f9fe82e19200ee33f175e38136517 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 14 Jul 2022 01:16:39 +0800 Subject: [PATCH] indicator: make callback field private --- pkg/indicator/ewma.go | 2 +- pkg/indicator/ewma_callbacks.go | 4 ++-- pkg/indicator/hull.go | 2 +- pkg/indicator/hull_callbacks.go | 4 ++-- pkg/indicator/macd.go | 2 +- pkg/indicator/macd_callbacks.go | 4 ++-- pkg/indicator/obv.go | 4 ++-- pkg/indicator/obv_callbacks.go | 4 ++-- pkg/indicator/rma.go | 17 ++++++++++------- pkg/indicator/rma_callbacks.go | 4 ++-- 10 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pkg/indicator/ewma.go b/pkg/indicator/ewma.go index 4335c1316..11c071967 100644 --- a/pkg/indicator/ewma.go +++ b/pkg/indicator/ewma.go @@ -20,7 +20,7 @@ type EWMA struct { Values types.Float64Slice LastOpenTime time.Time - UpdateCallbacks []func(value float64) + updateCallbacks []func(value float64) } func (inc *EWMA) Update(value float64) { diff --git a/pkg/indicator/ewma_callbacks.go b/pkg/indicator/ewma_callbacks.go index a0458ee7c..38fbacb26 100644 --- a/pkg/indicator/ewma_callbacks.go +++ b/pkg/indicator/ewma_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *EWMA) OnUpdate(cb func(value float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *EWMA) EmitUpdate(value float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(value) } } diff --git a/pkg/indicator/hull.go b/pkg/indicator/hull.go index 7eaf8ad70..03b021d68 100644 --- a/pkg/indicator/hull.go +++ b/pkg/indicator/hull.go @@ -16,7 +16,7 @@ type HULL struct { ma2 *EWMA result *EWMA - UpdateCallbacks []func(value float64) + updateCallbacks []func(value float64) } func (inc *HULL) Update(value float64) { diff --git a/pkg/indicator/hull_callbacks.go b/pkg/indicator/hull_callbacks.go index aa95c8dd9..5f6222f84 100644 --- a/pkg/indicator/hull_callbacks.go +++ b/pkg/indicator/hull_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *HULL) OnUpdate(cb func(value float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *HULL) EmitUpdate(value float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(value) } } diff --git a/pkg/indicator/macd.go b/pkg/indicator/macd.go index b1ced01c7..80183b730 100644 --- a/pkg/indicator/macd.go +++ b/pkg/indicator/macd.go @@ -26,7 +26,7 @@ type MACD struct { EndTime time.Time - UpdateCallbacks []func(value float64) + updateCallbacks []func(value float64) } func (inc *MACD) Update(x float64) { diff --git a/pkg/indicator/macd_callbacks.go b/pkg/indicator/macd_callbacks.go index a368fa625..cd8b1a8f6 100644 --- a/pkg/indicator/macd_callbacks.go +++ b/pkg/indicator/macd_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *MACD) OnUpdate(cb func(value float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *MACD) EmitUpdate(value float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(value) } } diff --git a/pkg/indicator/obv.go b/pkg/indicator/obv.go index db5688bd5..3fd663063 100644 --- a/pkg/indicator/obv.go +++ b/pkg/indicator/obv.go @@ -18,9 +18,9 @@ type OBV struct { types.IntervalWindow Values types.Float64Slice PrePrice float64 + EndTime time.Time - EndTime time.Time - UpdateCallbacks []func(value float64) + updateCallbacks []func(value float64) } func (inc *OBV) Update(price, volume float64) { diff --git a/pkg/indicator/obv_callbacks.go b/pkg/indicator/obv_callbacks.go index b0897152c..2b1ce69b1 100644 --- a/pkg/indicator/obv_callbacks.go +++ b/pkg/indicator/obv_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *OBV) OnUpdate(cb func(value float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *OBV) EmitUpdate(value float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(value) } } diff --git a/pkg/indicator/rma.go b/pkg/indicator/rma.go index 9e6b71fdb..933875ddd 100644 --- a/pkg/indicator/rma.go +++ b/pkg/indicator/rma.go @@ -13,13 +13,16 @@ import ( type RMA struct { types.SeriesBase types.IntervalWindow - Values types.Float64Slice - counter int - Adjust bool - tmp float64 - sum float64 - EndTime time.Time - UpdateCallbacks []func(value float64) + + Values types.Float64Slice + EndTime time.Time + + counter int + Adjust bool + tmp float64 + sum float64 + + updateCallbacks []func(value float64) } func (inc *RMA) Update(x float64) { diff --git a/pkg/indicator/rma_callbacks.go b/pkg/indicator/rma_callbacks.go index f5a40ca5e..e08b30668 100644 --- a/pkg/indicator/rma_callbacks.go +++ b/pkg/indicator/rma_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *RMA) OnUpdate(cb func(value float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *RMA) EmitUpdate(value float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(value) } }