bbgo: fix injection

This commit is contained in:
c9s 2022-07-21 12:33:29 +08:00
parent 7ce7a1b11c
commit de62d9dd67
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 17 additions and 0 deletions

View File

@ -473,6 +473,11 @@ func (session *ExchangeSession) Positions() map[string]*types.Position {
// MarketDataStore returns the market data store of a symbol
func (session *ExchangeSession) MarketDataStore(symbol string) (s *MarketDataStore, ok bool) {
s, ok = session.marketDataStores[symbol]
if !ok {
s = NewMarketDataStore(symbol)
session.marketDataStores[symbol] = s
return s, true
}
return s, ok
}

View File

@ -292,10 +292,22 @@ func (trader *Trader) injectFields() error {
return fmt.Errorf("market of symbol %s not found", symbol)
}
indicatorSet, ok := session.StandardIndicatorSet(symbol)
if !ok {
return fmt.Errorf("standardIndicatorSet of symbol %s not found", symbol)
}
store, ok := session.MarketDataStore(symbol)
if !ok {
return fmt.Errorf("marketDataStore of symbol %s not found", symbol)
}
if err := dynamic.ParseStructAndInject(strategy,
market,
session,
session.OrderExecutor,
indicatorSet,
store,
); err != nil {
return errors.Wrapf(err, "failed to inject object into %T", strategy)
}