cache: refactor moving from bbgo to pkg/cache

This commit is contained in:
austin362667 2022-01-14 16:10:05 +08:00
parent 734221028b
commit 91d2312c5c
5 changed files with 8 additions and 7 deletions

View File

@ -30,6 +30,7 @@ package backtest
import (
"context"
"fmt"
"github.com/c9s/bbgo/pkg/cache"
"sync"
"time"
@ -68,7 +69,7 @@ type Exchange struct {
func NewExchange(sourceName types.ExchangeName, sourceExchange types.Exchange, srv *service.BacktestService, config *bbgo.Backtest) (*Exchange, error) {
ex := sourceExchange
markets, err := bbgo.LoadExchangeMarketsWithCache(context.Background(), ex)
markets, err := cache.LoadExchangeMarketsWithCache(context.Background(), ex)
if err != nil {
return nil, err
}

View File

@ -3,6 +3,7 @@ package bbgo
import (
"context"
"fmt"
"github.com/c9s/bbgo/pkg/cache"
"strings"
"time"
@ -295,7 +296,7 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
if util.SetEnvVarBool("DISABLE_MARKETS_CACHE", &disableMarketsCache); disableMarketsCache {
markets, err = session.Exchange.QueryMarkets(ctx)
} else {
markets, err = LoadExchangeMarketsWithCache(ctx, session.Exchange)
markets, err = cache.LoadExchangeMarketsWithCache(ctx, session.Exchange)
if err != nil {
return err
}

View File

@ -1,4 +1,4 @@
package bbgo
package cache
import (
"context"

View File

@ -1,4 +1,4 @@
package bbgo
package cache
import (
"os"

View File

@ -3,6 +3,7 @@ package service
import (
"context"
"errors"
"github.com/c9s/bbgo/pkg/cache"
"time"
log "github.com/sirupsen/logrus"
@ -25,9 +26,7 @@ type SyncService struct {
func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, symbols ...string) error {
for _, symbol := range symbols {
log.Infof("syncing %s %s trades...", exchange.Name(), symbol)
// TODO: bbgo import cycle error
//markets, err := bbgo.LoadExchangeMarketsWithCache(ctx, exchange)
markets, err := exchange.QueryMarkets(ctx)
markets, err := cache.LoadExchangeMarketsWithCache(ctx, exchange)
if err != nil {
return err
}