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) { 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) { 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" "path"
"reflect" "reflect"
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/pkg/errors"
) )
type DataFetcher func() (interface{}, error) type DataFetcher func() (interface{}, error)
@ -75,4 +74,3 @@ func LoadExchangeMarketsWithCache(ctx context.Context, ex types.Exchange) (marke
}) })
return markets, err return markets, err
} }

View File

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