mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
indicator: improve kline stream backfill
This commit is contained in:
parent
dcb091cab1
commit
775ad7d906
|
@ -28,16 +28,21 @@ func (s *KLineStream) Last(i int) *types.KLine {
|
|||
func (s *KLineStream) AddSubscriber(f func(k types.KLine)) {
|
||||
s.OnUpdate(f)
|
||||
|
||||
if len(s.kLines) > 0 {
|
||||
// push historical klines to the subscriber
|
||||
for _, k := range s.kLines {
|
||||
f(k)
|
||||
}
|
||||
if len(s.kLines) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// push historical klines to the subscriber
|
||||
for _, k := range s.kLines {
|
||||
f(k)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *KLineStream) BackFill(kLines []types.KLine) {
|
||||
s.kLines = append(s.kLines, kLines...)
|
||||
for _, k := range kLines {
|
||||
s.kLines = append(s.kLines, k)
|
||||
s.EmitUpdate(k)
|
||||
}
|
||||
}
|
||||
|
||||
// KLines creates a KLine stream that pushes the klines to the subscribers
|
||||
|
|
Loading…
Reference in New Issue
Block a user