remove backtest flag from the sync command

This commit is contained in:
c9s 2020-11-11 16:11:41 +08:00
parent 24e5911140
commit 4bb5730cea

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"context" "context"
"fmt"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -17,13 +16,12 @@ func init() {
SyncCmd.Flags().String("exchange", "", "target exchange") SyncCmd.Flags().String("exchange", "", "target exchange")
SyncCmd.Flags().String("symbol", "BTCUSDT", "trading symbol") SyncCmd.Flags().String("symbol", "BTCUSDT", "trading symbol")
SyncCmd.Flags().String("since", "", "sync from time") SyncCmd.Flags().String("since", "", "sync from time")
SyncCmd.Flags().Bool("backtest", true, "sync backtest data")
RootCmd.AddCommand(SyncCmd) RootCmd.AddCommand(SyncCmd)
} }
var SyncCmd = &cobra.Command{ var SyncCmd = &cobra.Command{
Use: "sync", Use: "sync",
Short: "sync data. trades, orders and market data", Short: "sync trades, orders",
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background() ctx := context.Background()
@ -75,43 +73,6 @@ var SyncCmd = &cobra.Command{
} }
} }
backtest, err := cmd.Flags().GetBool("backtest")
if err != nil {
return err
}
if backtest {
backtestService := &service.BacktestService{DB: db}
if err := backtestService.Sync(ctx, exchange, symbol, startTime); err != nil {
return err
}
log.Info("synchronization done")
log.Infof("verifying backtesting data...")
for interval := range types.SupportedIntervals {
log.Infof("verifying %s kline data...", interval)
klineC, errC := backtestService.QueryKLinesCh(startTime, time.Now(), exchange, []string{symbol}, []types.Interval{interval})
var emptyKLine types.KLine
var prevKLine types.KLine
for k := range klineC {
fmt.Print(".")
if prevKLine != emptyKLine {
if prevKLine.StartTime.Add(interval.Duration()) != k.StartTime {
log.Errorf("kline corrupted at %+v", k)
}
}
prevKLine = k
}
fmt.Println()
if err := <-errC; err != nil {
return err
}
}
} else {
tradeService := &service.TradeService{DB: db} tradeService := &service.TradeService{DB: db}
orderService := &service.OrderService{DB: db} orderService := &service.OrderService{DB: db}
syncService := &service.SyncService{ syncService := &service.SyncService{
@ -130,7 +91,6 @@ var SyncCmd = &cobra.Command{
} }
log.Info("synchronization done") log.Info("synchronization done")
}
return nil return nil
}, },