diff --git a/pkg/service/backtest.go b/pkg/service/backtest.go index cb9b28d51..3ccb26857 100644 --- a/pkg/service/backtest.go +++ b/pkg/service/backtest.go @@ -52,7 +52,7 @@ func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange type q := &batch.KLineBatchQuery{Exchange: exchange} return q.Query(ctx, symbol, interval, startTime, endTime) }, - // BatchInsertBuffer: 500, + BatchInsertBuffer: 500, // BatchInsert: func(obj interface{}) error { // kLines := obj.([]types.KLine) // return s.BatchInsert(kLines) @@ -373,7 +373,7 @@ func (s *BacktestService) SyncPartial(ctx context.Context, ex types.Exchange, sy } for _, timeRange := range timeRanges { - err = s.SyncKLineByInterval(ctx, ex, symbol, interval, timeRange.Start.Add(time.Second), timeRange.End) + err = s.SyncKLineByInterval(ctx, ex, symbol, interval, timeRange.Start.Add(time.Second), timeRange.End.Add(-time.Second)) if err != nil { return err } diff --git a/pkg/service/backtest_test.go b/pkg/service/backtest_test.go index 486ab552e..ca863e287 100644 --- a/pkg/service/backtest_test.go +++ b/pkg/service/backtest_test.go @@ -100,6 +100,7 @@ func TestBacktestService_SyncPartial(t *testing.T) { timeRanges, err := service.FindMissingTimeRanges(ctx, ex, symbol, types.Interval1h, startTime1, endTime2) assert.NoError(t, err) assert.NotEmpty(t, timeRanges) + assert.Len(t, timeRanges, 1) t.Run("fill missing time ranges", func(t *testing.T) { err = service.SyncPartial(ctx, ex, symbol, types.Interval1h, startTime1, endTime2) @@ -109,19 +110,6 @@ func TestBacktestService_SyncPartial(t *testing.T) { assert.NoError(t, err) assert.Empty(t, timeRanges2) }) - - t.Run("extend time ranges", func(t *testing.T) { - startTime3 := startTime1.AddDate(0, 0, -3) - endTime3 := endTime2.AddDate(0, 0, 3) - - err = service.SyncPartial(ctx, ex, symbol, types.Interval1h, startTime3, endTime3) - assert.NoError(t, err, "sync partial should not return error") - - timeRanges3, err := service.FindMissingTimeRanges(ctx, ex, symbol, types.Interval1h, startTime3, endTime3) - assert.NoError(t, err) - assert.Empty(t, timeRanges3) - }) - } func TestBacktestService_FindMissingTimeRanges(t *testing.T) {