From 5ec05668886f5a4d357f6fceb300d8e8957c531e Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 2 May 2021 23:46:16 +0800 Subject: [PATCH] add more injection checks --- pkg/bbgo/trader.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index d2665663d..8635d34e8 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -211,7 +211,7 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si } if symbol, ok := isSymbolBasedStrategy(rs); ok { - log.Debugf("found symbol based strategy from %s", rs.Type()) + log.Infof("found symbol based strategy from %s", rs.Type()) if _, ok := hasField(rs, "Market"); ok { if market, ok := session.Market(symbol); ok { // let's make the market object passed by pointer @@ -223,18 +223,24 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si // StandardIndicatorSet if _, ok := hasField(rs, "StandardIndicatorSet"); ok { - if indicatorSet, ok := session.StandardIndicatorSet(symbol); ok { - if err := injectField(rs, "StandardIndicatorSet", indicatorSet, true); err != nil { - return errors.Wrapf(err, "failed to inject StandardIndicatorSet on %T", strategy) - } + indicatorSet, ok := session.StandardIndicatorSet(symbol) + if !ok { + return fmt.Errorf("standardIndicatorSet of symbol %s not found", symbol) + } + + if err := injectField(rs, "StandardIndicatorSet", indicatorSet, true); err != nil { + return errors.Wrapf(err, "failed to inject StandardIndicatorSet on %T", strategy) } } if _, ok := hasField(rs, "MarketDataStore"); ok { - if store, ok := session.MarketDataStore(symbol); ok { - if err := injectField(rs, "MarketDataStore", store, true); err != nil { - return errors.Wrapf(err, "failed to inject MarketDataStore on %T", strategy) - } + store, ok := session.MarketDataStore(symbol) + if !ok { + return fmt.Errorf("marketDataStore of symbol %s not found", symbol) + } + + if err := injectField(rs, "MarketDataStore", store, true); err != nil { + return errors.Wrapf(err, "failed to inject MarketDataStore on %T", strategy) } } }