From 08a264d4eb6dbf1716610a67fd15dc5ed7c57ad5 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 7 Dec 2021 21:29:40 +0800 Subject: [PATCH] add futures exchange check in the markets cache --- pkg/bbgo/cache.go | 10 +++++++++- pkg/types/margin.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/bbgo/cache.go b/pkg/bbgo/cache.go index 8a4ca3fcf..09dad0d4e 100644 --- a/pkg/bbgo/cache.go +++ b/pkg/bbgo/cache.go @@ -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) { - 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 markets, err diff --git a/pkg/types/margin.go b/pkg/types/margin.go index 82bf54a5c..09e30d97e 100644 --- a/pkg/types/margin.go +++ b/pkg/types/margin.go @@ -4,6 +4,7 @@ import "github.com/c9s/bbgo/pkg/fixedpoint" type FuturesExchange interface { UseFutures() + GetFuturesSettings() FuturesSettings } type FuturesSettings struct {