mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
feature: add ExchangePublic
This commit is contained in:
parent
c5dbd4b961
commit
ec45ad3bdc
6
pkg/cache/cache.go
vendored
6
pkg/cache/cache.go
vendored
|
@ -126,7 +126,7 @@ func WithCache(key string, obj interface{}, fetcher DataFetcher) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (markets types.MarketMap, err error) {
|
||||
func LoadExchangeMarketsWithCache(ctx context.Context, ex types.ExchangePublic) (markets types.MarketMap, err error) {
|
||||
inMem, ok := util.GetEnvVarBool("USE_MARKETS_CACHE_IN_MEMORY")
|
||||
if ok && inMem {
|
||||
return loadMarketsFromMem(ctx, ex)
|
||||
|
@ -137,7 +137,7 @@ func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (marke
|
|||
}
|
||||
|
||||
// loadMarketsFromMem is useful for one process to run multiple bbgos in different go routines.
|
||||
func loadMarketsFromMem(ctx context.Context, ex types.Exchange) (markets types.MarketMap, _ error) {
|
||||
func loadMarketsFromMem(ctx context.Context, ex types.ExchangePublic) (markets types.MarketMap, _ error) {
|
||||
exName := ex.Name().String()
|
||||
if globalMarketMemCache.IsOutdated(exName) {
|
||||
op := func() error {
|
||||
|
@ -162,7 +162,7 @@ func loadMarketsFromMem(ctx context.Context, ex types.Exchange) (markets types.M
|
|||
return rst, nil
|
||||
}
|
||||
|
||||
func loadMarketsFromFile(ctx context.Context, ex types.Exchange) (markets types.MarketMap, err error) {
|
||||
func loadMarketsFromFile(ctx context.Context, ex types.ExchangePublic) (markets types.MarketMap, err error) {
|
||||
key := fmt.Sprintf("%s-markets", ex.Name())
|
||||
if futureExchange, implemented := ex.(types.FuturesExchange); implemented {
|
||||
settings := futureExchange.GetFuturesSettings()
|
||||
|
|
2
pkg/cache/cache_test.go
vendored
2
pkg/cache/cache_test.go
vendored
|
@ -67,7 +67,7 @@ func Test_loadMarketsFromMem(t *testing.T) {
|
|||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
mockEx := mocks.NewMockExchange(mockCtrl)
|
||||
mockEx := mocks.NewMockExchangePublic(mockCtrl)
|
||||
mockEx.EXPECT().Name().Return(types.ExchangeName("max")).AnyTimes()
|
||||
mockEx.EXPECT().QueryMarkets(gomock.Any()).Return(nil, errors.New("faked")).Times(1)
|
||||
mockEx.EXPECT().QueryMarkets(gomock.Any()).Return(types.MarketMap{
|
||||
|
|
|
@ -87,6 +87,12 @@ type Exchange interface {
|
|||
ExchangeTradeService
|
||||
}
|
||||
|
||||
//go:generate mockgen -destination=mocks/mock_exchange_public.go -package=mocks . ExchangePublic
|
||||
type ExchangePublic interface {
|
||||
ExchangeMinimal
|
||||
ExchangeMarketDataService
|
||||
}
|
||||
|
||||
// ExchangeBasic is the new type for replacing the original Exchange interface
|
||||
type ExchangeBasic = Exchange
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user