fix: don't sync on reward/withdraw/deposit records when using testnet

This commit is contained in:
zenix 2022-03-17 21:06:40 +09:00
parent 36a746d415
commit 9cf835728c
2 changed files with 28 additions and 21 deletions

View File

@ -40,7 +40,6 @@ func (s *OrderService) Sync(ctx context.Context, exchange types.Exchange, symbol
symbol = futuresSettings.IsolatedFuturesSymbol
}
}
records, err := s.QueryLast(exchange.Name(), symbol, isMargin, isFutures, isIsolated, 50)
if err != nil {

View File

@ -3,6 +3,8 @@ package service
import (
"context"
"errors"
"os"
"strconv"
"time"
"github.com/c9s/bbgo/pkg/cache"
@ -23,6 +25,11 @@ type SyncService struct {
DepositService *DepositService
}
func paperTrade() bool {
v, err := strconv.ParseBool(os.Getenv("PAPER_TRADE"))
return err == nil && v
}
// SyncSessionSymbols syncs the trades from the given exchange session
func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, symbols ...string) error {
markets, err := cache.LoadExchangeMarketsWithCache(ctx, exchange)
@ -44,27 +51,28 @@ func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exc
}
}
log.Infof("syncing %s deposit records...", exchange.Name())
if err := s.DepositService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
if !paperTrade() {
log.Infof("syncing %s deposit records...", exchange.Name())
if err := s.DepositService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
log.Infof("syncing %s withdraw records...", exchange.Name())
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
log.Infof("syncing %s reward records...", exchange.Name())
if err := s.RewardService.Sync(ctx, exchange); err != nil {
if err != ErrExchangeRewardServiceNotImplemented {
log.Infof("%s reward service is not supported", exchange.Name())
return err
}
}
}
log.Infof("syncing %s withdraw records...", exchange.Name())
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
log.Infof("syncing %s reward records...", exchange.Name())
if err := s.RewardService.Sync(ctx, exchange); err != nil {
if err != ErrExchangeRewardServiceNotImplemented {
log.Infof("%s reward service is not supported", exchange.Name())
return err
}
}
return nil
}