check runtime registered strategies

This commit is contained in:
c9s 2020-10-23 14:13:16 +08:00
parent 6e033461bb
commit 407db84689

View File

@ -57,10 +57,12 @@ type PnLReporter struct {
}
type Config struct {
Imports []string `json:"imports" yaml:"imports"`
ExchangeStrategies []SingleExchangeStrategyConfig
CrossExchangeStrategies []bbgo.CrossExchangeStrategy
PnLReporters []PnLReporter `json:"reportPnL"`
PnLReporters []PnLReporter `json:"reportPnL" yaml:"reportPnL"`
}
type Stash map[string]interface{}
@ -118,6 +120,11 @@ func loadReportPnL(config *Config, stash Stash) error {
}
func loadCrossExchangeStrategies(config *Config, stash Stash) (err error) {
if len(bbgo.LoadedCrossExchangeStrategies) == 0 {
return errors.New("no cross exchange strategy is registered")
}
exchangeStrategiesConf, ok := stash["crossExchangeStrategies"]
if !ok {
return nil
@ -151,6 +158,10 @@ func loadCrossExchangeStrategies(config *Config, stash Stash) (err error) {
}
func loadExchangeStrategies(config *Config, stash Stash) (err error) {
if len(bbgo.LoadedExchangeStrategies) == 0 {
return errors.New("no exchange strategy is registered")
}
exchangeStrategiesConf, ok := stash["exchangeStrategies"]
if !ok {
return nil
@ -161,6 +172,7 @@ func loadExchangeStrategies(config *Config, stash Stash) (err error) {
return errors.New("expecting list in exchangeStrategies")
}
for _, entry := range configList {
configStash, ok := entry.(Stash)
if !ok {
@ -176,6 +188,7 @@ func loadExchangeStrategies(config *Config, stash Stash) (err error) {
}
}
for id, conf := range configStash {
// look up the real struct type
if st, ok := bbgo.LoadedExchangeStrategies[id]; ok {