From de00e5fa88e2d68173b88421f49acab92e251286 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 19 Jun 2023 17:03:38 +0800 Subject: [PATCH] scmaker: preload indicators --- pkg/strategy/scmaker/strategy.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/strategy/scmaker/strategy.go b/pkg/strategy/scmaker/strategy.go index 83c1d34d6..5248a6a78 100644 --- a/pkg/strategy/scmaker/strategy.go +++ b/pkg/strategy/scmaker/strategy.go @@ -179,20 +179,36 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se return nil } +func (s *Strategy) preloadKLines(inc *indicator.KLineStream, session *bbgo.ExchangeSession, symbol string, interval types.Interval) { + if store, ok := session.MarketDataStore(symbol); ok { + if kLinesData, ok := store.KLinesOfInterval(interval); ok { + for _, k := range *kLinesData { + inc.EmitUpdate(k) + } + } + } +} + func (s *Strategy) initializeMidPriceEMA(session *bbgo.ExchangeSession) { kLines := indicator.KLines(session.MarketDataStream, s.Symbol, s.MidPriceEMA.Interval) s.ewma = indicator.EWMA2(indicator.ClosePrices(kLines), s.MidPriceEMA.Window) + + s.preloadKLines(kLines, session, s.Symbol, s.MidPriceEMA.Interval) } func (s *Strategy) initializeIntensityIndicator(session *bbgo.ExchangeSession) { kLines := indicator.KLines(session.MarketDataStream, s.Symbol, s.StrengthInterval) s.intensity = Intensity(kLines, 10) + + s.preloadKLines(kLines, session, s.Symbol, s.StrengthInterval) } func (s *Strategy) initializePriceRangeBollinger(session *bbgo.ExchangeSession) { kLines := indicator.KLines(session.MarketDataStream, s.Symbol, s.PriceRangeBollinger.Interval) closePrices := indicator.ClosePrices(kLines) s.boll = indicator.BOLL2(closePrices, s.PriceRangeBollinger.Window, s.PriceRangeBollinger.K) + + s.preloadKLines(kLines, session, s.Symbol, s.PriceRangeBollinger.Interval) } func (s *Strategy) placeAdjustmentOrders(ctx context.Context) {