From 1079757833a7396d99df668ede54cdd46a4b713c Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 21 Jul 2022 12:35:38 +0800 Subject: [PATCH] bbgo: bind market data store to market data stream when allocating new instance --- pkg/bbgo/session.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index e75afc7ee..6300b330f 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -365,12 +365,17 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ orderStore.BindStream(session.UserDataStream) session.orderStores[symbol] = orderStore - marketDataStore := NewMarketDataStore(symbol) - marketDataStore.BindStream(session.MarketDataStream) - session.marketDataStores[symbol] = marketDataStore + if _, ok := session.marketDataStores[symbol]; !ok { + marketDataStore := NewMarketDataStore(symbol) + marketDataStore.BindStream(session.MarketDataStream) + session.marketDataStores[symbol] = marketDataStore + } - standardIndicatorSet := NewStandardIndicatorSet(symbol, session.MarketDataStream, marketDataStore) - session.standardIndicatorSets[symbol] = standardIndicatorSet + if _, ok := session.standardIndicatorSets[symbol]; !ok { + marketDataStore := session.marketDataStores[symbol] + standardIndicatorSet := NewStandardIndicatorSet(symbol, session.MarketDataStream, marketDataStore) + session.standardIndicatorSets[symbol] = standardIndicatorSet + } // used kline intervals by the given symbol var klineSubscriptions = map[types.Interval]struct{}{} @@ -475,6 +480,7 @@ func (session *ExchangeSession) MarketDataStore(symbol string) (s *MarketDataSto s, ok = session.marketDataStores[symbol] if !ok { s = NewMarketDataStore(symbol) + s.BindStream(session.MarketDataStream) session.marketDataStores[symbol] = s return s, true }