pivotshort: fix kline history loading

This commit is contained in:
c9s 2022-06-29 11:23:05 +08:00
parent fc3e76204a
commit 38920dfc7a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -226,9 +226,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.pivot = &indicator.Pivot{IntervalWindow: s.IntervalWindow} s.pivot = &indicator.Pivot{IntervalWindow: s.IntervalWindow}
s.pivot.Bind(store) s.pivot.Bind(store)
if kLinesP, ok := store.KLinesOfInterval(s.IntervalWindow.Interval); ok {
s.pivot.Update(*kLinesP) lastKLine := s.preloadPivot(s.pivot, store)
}
// update pivot low data // update pivot low data
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) { session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
@ -263,13 +262,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
} }
if s.BounceShort != nil && s.BounceShort.Enabled { if s.BounceShort != nil && s.BounceShort.Enabled {
session.UserDataStream.OnStart(func() {
lastKLine := s.preloadPivot(s.pivot, store)
if s.resistancePivot != nil { if s.resistancePivot != nil {
s.preloadPivot(s.resistancePivot, store) s.preloadPivot(s.resistancePivot, store)
} }
session.UserDataStream.OnStart(func() {
if lastKLine == nil { if lastKLine == nil {
return return
} }
@ -484,7 +481,6 @@ func (s *Strategy) preloadPivot(pivot *indicator.Pivot, store *bbgo.MarketDataSt
} }
last := (*klines)[len(*klines)-1] last := (*klines)[len(*klines)-1]
log.Infof("last %s price: %f", s.Symbol, last.Close.Float64())
log.Debugf("updating pivot indicator: %d klines", len(*klines)) log.Debugf("updating pivot indicator: %d klines", len(*klines))
for i := pivot.Window; i < len(*klines); i++ { for i := pivot.Window; i < len(*klines); i++ {