mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
41 lines
718 B
Go
41 lines
718 B
Go
package indicator
|
|
|
|
import (
|
|
"github.com/c9s/bbgo/pkg/datatype/floats"
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
)
|
|
|
|
//go:generate callbackgen -type Float64Updater
|
|
type Float64Updater struct {
|
|
updateCallbacks []func(v float64)
|
|
}
|
|
|
|
type Float64Series struct {
|
|
types.SeriesBase
|
|
Float64Updater
|
|
slice floats.Slice
|
|
}
|
|
|
|
func NewFloat64Series(v ...float64) Float64Series {
|
|
s := Float64Series{}
|
|
s.slice = v
|
|
s.SeriesBase.Series = s.slice
|
|
return s
|
|
}
|
|
|
|
func (f *Float64Series) Last() float64 {
|
|
return f.slice.Last()
|
|
}
|
|
|
|
func (f *Float64Series) Index(i int) float64 {
|
|
length := len(f.slice)
|
|
if length == 0 || length-i-1 < 0 {
|
|
return 0
|
|
}
|
|
return f.slice[length-i-1]
|
|
}
|
|
|
|
func (f *Float64Series) Length() int {
|
|
return len(f.slice)
|
|
}
|