add more injection checks

This commit is contained in:
c9s 2021-05-02 23:46:16 +08:00
parent 822a010932
commit 5ec0566888

View File

@ -211,7 +211,7 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si
} }
if symbol, ok := isSymbolBasedStrategy(rs); ok { 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 _, ok := hasField(rs, "Market"); ok {
if market, ok := session.Market(symbol); ok { if market, ok := session.Market(symbol); ok {
// let's make the market object passed by pointer // let's make the market object passed by pointer
@ -223,21 +223,27 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si
// StandardIndicatorSet // StandardIndicatorSet
if _, ok := hasField(rs, "StandardIndicatorSet"); ok { if _, ok := hasField(rs, "StandardIndicatorSet"); ok {
if indicatorSet, ok := session.StandardIndicatorSet(symbol); ok { 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 { if err := injectField(rs, "StandardIndicatorSet", indicatorSet, true); err != nil {
return errors.Wrapf(err, "failed to inject StandardIndicatorSet on %T", strategy) return errors.Wrapf(err, "failed to inject StandardIndicatorSet on %T", strategy)
} }
} }
}
if _, ok := hasField(rs, "MarketDataStore"); ok { if _, ok := hasField(rs, "MarketDataStore"); ok {
if store, ok := session.MarketDataStore(symbol); ok { 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 { if err := injectField(rs, "MarketDataStore", store, true); err != nil {
return errors.Wrapf(err, "failed to inject MarketDataStore on %T", strategy) return errors.Wrapf(err, "failed to inject MarketDataStore on %T", strategy)
} }
} }
} }
}
// If the strategy has Validate() method, run it and check the error // If the strategy has Validate() method, run it and check the error
if v, ok := strategy.(Validator); ok { if v, ok := strategy.(Validator); ok {