From 38920dfc7a3dbb06d2051e4ef1c000099a801f90 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 29 Jun 2022 11:23:05 +0800 Subject: [PATCH] pivotshort: fix kline history loading --- pkg/strategy/pivotshort/strategy.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index b39a0fe1c..69cfa6cdb 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -226,9 +226,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.pivot = &indicator.Pivot{IntervalWindow: s.IntervalWindow} 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 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.resistancePivot != nil { + s.preloadPivot(s.resistancePivot, store) + } + session.UserDataStream.OnStart(func() { - lastKLine := s.preloadPivot(s.pivot, store) - - if s.resistancePivot != nil { - s.preloadPivot(s.resistancePivot, store) - } - if lastKLine == nil { return } @@ -484,7 +481,6 @@ func (s *Strategy) preloadPivot(pivot *indicator.Pivot, store *bbgo.MarketDataSt } 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)) for i := pivot.Window; i < len(*klines); i++ {