From 168cb355fc3f46a34aa0971801fff523c68fca76 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 Oct 2020 12:27:11 +0800 Subject: [PATCH] add accessor to MarketDataStore --- pkg/bbgo/environment.go | 4 ++-- pkg/bbgo/session.go | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index fd6da1b7c..8ca1de810 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -102,7 +102,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) { session.LastPrices[symbol] = currentPrice - session.MarketDataStores[symbol] = store.NewMarketDataStore(symbol) + session.marketDataStores[symbol] = store.NewMarketDataStore(symbol) } log.Infof("querying balances...") @@ -121,7 +121,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) { // update last prices stream.OnKLineClosed(func(kline types.KLine) { session.LastPrices[kline.Symbol] = kline.Close - session.MarketDataStores[kline.Symbol].AddKLine(kline) + session.marketDataStores[kline.Symbol].AddKLine(kline) }) stream.OnTrade(func(trade *types.Trade) { diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index c5a15fd76..c5ec843a8 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -30,21 +30,26 @@ type ExchangeSession struct { // map: symbol -> []trade Trades map[string][]types.Trade - MarketDataStores map[string]*store.MarketDataStore + marketDataStores map[string]*store.MarketDataStore } func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession { return &ExchangeSession{ - Name: name, - Exchange: exchange, - Subscriptions: make(map[types.Subscription]types.Subscription), - Markets: make(map[string]types.Market), - Trades: make(map[string][]types.Trade), - LastPrices: make(map[string]float64), - MarketDataStores: make(map[string]*store.MarketDataStore), + Name: name, + Exchange: exchange, + Subscriptions: make(map[types.Subscription]types.Subscription), + Markets: make(map[string]types.Market), + Trades: make(map[string][]types.Trade), + LastPrices: make(map[string]float64), + marketDataStores: make(map[string]*store.MarketDataStore), } } +func (session *ExchangeSession) MarketDataStore(symbol string) (s *store.MarketDataStore, ok bool) { + s, ok = session.marketDataStores[symbol] + return s, ok +} + // Subscribe save the subscription info, later it will be assigned to the stream func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession { sub := types.Subscription{