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

View File

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

View File

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

View File

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

View File

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