add futures exchange check in the markets cache

This commit is contained in:
c9s 2021-12-07 21:29:40 +08:00
parent 245905a25a
commit 08a264d4eb
2 changed files with 10 additions and 1 deletions

View File

@ -62,7 +62,15 @@ func WithCache(key string, obj interface{}, fetcher DataFetcher) error {
} }
func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (markets types.MarketMap, err error) { func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (markets types.MarketMap, err error) {
err = WithCache(fmt.Sprintf("%s-markets", ex.Name()), &markets, func() (interface{}, error) { key := fmt.Sprintf("%s-markets", ex.Name())
if futureExchange, implemented := ex.(types.FuturesExchange) ; implemented {
settings := futureExchange.GetFuturesSettings()
if settings.IsFutures {
key = fmt.Sprintf("%s-futures-markets", ex.Name())
}
}
err = WithCache(key, &markets, func() (interface{}, error) {
return ex.QueryMarkets(ctx) return ex.QueryMarkets(ctx)
}) })
return markets, err return markets, err

View File

@ -4,6 +4,7 @@ import "github.com/c9s/bbgo/pkg/fixedpoint"
type FuturesExchange interface { type FuturesExchange interface {
UseFutures() UseFutures()
GetFuturesSettings() FuturesSettings
} }
type FuturesSettings struct { type FuturesSettings struct {