indicator/pivotlow: drop the legacy CalculateAndUpdate

This commit is contained in:
c9s 2022-07-26 17:32:56 +08:00
parent 0df321c880
commit 16c62eab2b
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 0 additions and 39 deletions

View File

@ -22,12 +22,6 @@ type KLinePusher interface {
PushK(k types.KLine) PushK(k types.KLine)
} }
// KLineLoader provides an interface for API user to load history klines to the indicator.
// The indicator implements its own way to calculate the values from the given history kline array.
type KLineLoader interface {
LoadK(allKLines []types.KLine)
}
type KLineCalculateUpdater interface { type KLineCalculateUpdater interface {
CalculateAndUpdate(allKLines []types.KLine) CalculateAndUpdate(allKLines []types.KLine)
} }

View File

@ -9,8 +9,6 @@ import (
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
//go:generate callbackgen -type PivotLow //go:generate callbackgen -type PivotLow
type PivotLow struct { type PivotLow struct {
types.IntervalWindow types.IntervalWindow
@ -55,37 +53,6 @@ func (inc *PivotLow) PushK(k types.KLine) {
inc.EmitUpdate(inc.Last()) inc.EmitUpdate(inc.Last())
} }
func (inc *PivotLow) LoadK(allKLines []types.KLine) {
for _, k := range allKLines {
inc.PushK(k)
}
}
func (inc *PivotLow) CalculateAndUpdate(allKLines []types.KLine) {
if len(inc.Values) == 0 {
for _, k := range allKLines {
inc.PushK(k)
}
inc.EmitUpdate(inc.Last())
} else {
k := allKLines[len(allKLines)-1]
inc.PushK(k)
inc.EmitUpdate(inc.Last())
}
}
func (inc *PivotLow) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
if inc.Interval != interval {
return
}
inc.CalculateAndUpdate(window)
}
func (inc *PivotLow) Bind(updater KLineWindowUpdater) {
updater.OnKLineWindowUpdate(inc.handleKLineWindowUpdate)
}
func calculatePivotLow(lows types.Float64Slice, window int) (float64, error) { func calculatePivotLow(lows types.Float64Slice, window int) (float64, error) {
length := len(lows) length := len(lows)
if length == 0 || length < window { if length == 0 || length < window {