mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
cache: refactor moving from bbgo to pkg/cache
This commit is contained in:
parent
734221028b
commit
91d2312c5c
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
2
pkg/bbgo/cache.go → pkg/cache/cache.go
vendored
2
pkg/bbgo/cache.go → pkg/cache/cache.go
vendored
|
@ -1,4 +1,4 @@
|
||||||
package bbgo
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
2
pkg/bbgo/home.go → pkg/cache/home.go
vendored
2
pkg/bbgo/home.go → pkg/cache/home.go
vendored
|
@ -1,4 +1,4 @@
|
||||||
package bbgo
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user