indicator: make callback field private

This commit is contained in:
c9s 2022-07-14 01:16:39 +08:00
parent 2a3118a086
commit b2538b6960
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
10 changed files with 25 additions and 22 deletions

View File

@ -20,7 +20,7 @@ type EWMA struct {
Values types.Float64Slice Values types.Float64Slice
LastOpenTime time.Time LastOpenTime time.Time
UpdateCallbacks []func(value float64) updateCallbacks []func(value float64)
} }
func (inc *EWMA) Update(value float64) { func (inc *EWMA) Update(value float64) {

View File

@ -5,11 +5,11 @@ package indicator
import () import ()
func (inc *EWMA) OnUpdate(cb func(value float64)) { 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) { func (inc *EWMA) EmitUpdate(value float64) {
for _, cb := range inc.UpdateCallbacks { for _, cb := range inc.updateCallbacks {
cb(value) cb(value)
} }
} }

View File

@ -16,7 +16,7 @@ type HULL struct {
ma2 *EWMA ma2 *EWMA
result *EWMA result *EWMA
UpdateCallbacks []func(value float64) updateCallbacks []func(value float64)
} }
func (inc *HULL) Update(value float64) { func (inc *HULL) Update(value float64) {

View File

@ -5,11 +5,11 @@ package indicator
import () import ()
func (inc *HULL) OnUpdate(cb func(value float64)) { 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) { func (inc *HULL) EmitUpdate(value float64) {
for _, cb := range inc.UpdateCallbacks { for _, cb := range inc.updateCallbacks {
cb(value) cb(value)
} }
} }

View File

@ -26,7 +26,7 @@ type MACD struct {
EndTime time.Time EndTime time.Time
UpdateCallbacks []func(value float64) updateCallbacks []func(value float64)
} }
func (inc *MACD) Update(x float64) { func (inc *MACD) Update(x float64) {

View File

@ -5,11 +5,11 @@ package indicator
import () import ()
func (inc *MACD) OnUpdate(cb func(value float64)) { 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) { func (inc *MACD) EmitUpdate(value float64) {
for _, cb := range inc.UpdateCallbacks { for _, cb := range inc.updateCallbacks {
cb(value) cb(value)
} }
} }

View File

@ -18,9 +18,9 @@ type OBV struct {
types.IntervalWindow types.IntervalWindow
Values types.Float64Slice Values types.Float64Slice
PrePrice float64 PrePrice float64
EndTime time.Time
EndTime time.Time updateCallbacks []func(value float64)
UpdateCallbacks []func(value float64)
} }
func (inc *OBV) Update(price, volume float64) { func (inc *OBV) Update(price, volume float64) {

View File

@ -5,11 +5,11 @@ package indicator
import () import ()
func (inc *OBV) OnUpdate(cb func(value float64)) { 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) { func (inc *OBV) EmitUpdate(value float64) {
for _, cb := range inc.UpdateCallbacks { for _, cb := range inc.updateCallbacks {
cb(value) cb(value)
} }
} }

View File

@ -13,13 +13,16 @@ import (
type RMA struct { type RMA struct {
types.SeriesBase types.SeriesBase
types.IntervalWindow types.IntervalWindow
Values types.Float64Slice
counter int Values types.Float64Slice
Adjust bool EndTime time.Time
tmp float64
sum float64 counter int
EndTime time.Time Adjust bool
UpdateCallbacks []func(value float64) tmp float64
sum float64
updateCallbacks []func(value float64)
} }
func (inc *RMA) Update(x float64) { func (inc *RMA) Update(x float64) {

View File

@ -5,11 +5,11 @@ package indicator
import () import ()
func (inc *RMA) OnUpdate(cb func(value float64)) { 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) { func (inc *RMA) EmitUpdate(value float64) {
for _, cb := range inc.UpdateCallbacks { for _, cb := range inc.updateCallbacks {
cb(value) cb(value)
} }
} }