fix markets info cache

This commit is contained in:
c9s 2021-12-08 17:26:25 +08:00
parent e030b87e4e
commit d52edce40b
3 changed files with 28 additions and 32 deletions

View File

@ -289,7 +289,7 @@ func (e Exchange) PlatformFeeCurrency() string {
}
func (e Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
return e.publicExchange.QueryMarkets(ctx)
return bbgo.LoadExchangeMarketsWithCache(ctx, e.publicExchange)
}
func (e Exchange) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []types.Deposit, err error) {

View File

@ -9,9 +9,8 @@ import (
"path"
"reflect"
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/types"
"github.com/pkg/errors"
)
type DataFetcher func() (interface{}, error)
@ -75,4 +74,3 @@ func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (marke
})
return markets, err
}

View File

@ -8,13 +8,11 @@ import (
"github.com/c9s/bbgo/pkg/cmd/cmdutil"
"github.com/c9s/bbgo/pkg/fixedpoint"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/indicator"
"github.com/c9s/bbgo/pkg/service"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
log "github.com/sirupsen/logrus"
)
var (
@ -265,17 +263,18 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
var log = log.WithField("session", session.Name)
if !viper.GetBool("bbgo-markets-cache") {
markets, err := session.Exchange.QueryMarkets(ctx)
// load markets first
var disableMarketsCache = false
var markets types.MarketMap
var err error
if util.SetEnvVarBool("DISABLE_MARKETS_CACHE", &disableMarketsCache); disableMarketsCache {
markets, err = session.Exchange.QueryMarkets(ctx)
} else {
markets, err = LoadExchangeMarketsWithCache(ctx, session.Exchange)
if err != nil {
return err
}
session.markets = markets
} else {
// load markets first
var markets, err = LoadExchangeMarketsWithCache(ctx, session.Exchange)
if err != nil {
return err
}
if len(markets) == 0 {
@ -283,7 +282,6 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
}
session.markets = markets
}
// query and initialize the balances
log.Infof("querying balances from session %s...", session.Name)