mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix: batch query exit issue
- remove errC case (this channel is closed earlier) - add empty data range test case for finding missing time range
This commit is contained in:
parent
e1225d4127
commit
a6d18a87f5
|
@ -1226,11 +1226,11 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type
|
|||
Limit(limit)
|
||||
|
||||
if options.StartTime != nil {
|
||||
req.StartTime(options.StartTime.UnixNano() / int64(time.Millisecond))
|
||||
req.StartTime(options.StartTime.UnixMilli())
|
||||
}
|
||||
|
||||
if options.EndTime != nil {
|
||||
req.EndTime(options.EndTime.UnixNano() / int64(time.Millisecond))
|
||||
req.EndTime(options.EndTime.UnixMilli())
|
||||
}
|
||||
|
||||
resp, err := req.Do(ctx)
|
||||
|
|
|
@ -367,7 +367,7 @@ func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Ex
|
|||
}
|
||||
|
||||
var timeRanges []TimeRange
|
||||
var lastTime time.Time
|
||||
var lastTime = since
|
||||
var intervalDuration = interval.Duration()
|
||||
for rows.Next() {
|
||||
var tt types.Time
|
||||
|
@ -376,7 +376,7 @@ func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Ex
|
|||
}
|
||||
|
||||
var t = time.Time(tt)
|
||||
if lastTime != (time.Time{}) && t.Sub(lastTime) > intervalDuration {
|
||||
if t.Sub(lastTime) > intervalDuration {
|
||||
timeRanges = append(timeRanges, TimeRange{
|
||||
Start: lastTime,
|
||||
End: t,
|
||||
|
@ -386,6 +386,13 @@ func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Ex
|
|||
lastTime = t
|
||||
}
|
||||
|
||||
if lastTime.Before(until) {
|
||||
timeRanges = append(timeRanges, TimeRange{
|
||||
Start: lastTime,
|
||||
End: until,
|
||||
})
|
||||
}
|
||||
|
||||
return timeRanges, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,31 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func TestBacktestService_FindMissingTimeRanges_EmptyData(t *testing.T) {
|
||||
db, err := prepareDB(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
defer db.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
dbx := sqlx.NewDb(db.DB, "sqlite3")
|
||||
|
||||
ex, err := exchange.NewPublic(types.ExchangeBinance)
|
||||
assert.NoError(t, err)
|
||||
|
||||
service := &BacktestService{DB: dbx}
|
||||
|
||||
symbol := "BTCUSDT"
|
||||
now := time.Now()
|
||||
startTime1 := now.AddDate(0, 0, -7).Truncate(time.Hour)
|
||||
endTime1 := now.AddDate(0, 0, -6).Truncate(time.Hour)
|
||||
timeRanges, err := service.FindMissingTimeRanges(ctx, ex, symbol, types.Interval1h, startTime1, endTime1)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, timeRanges)
|
||||
}
|
||||
|
||||
func TestBacktestService_QueryExistingDataRange(t *testing.T) {
|
||||
db, err := prepareDB(t)
|
||||
if err != nil {
|
||||
|
|
|
@ -89,9 +89,6 @@ func (sel SyncTask) execute(ctx context.Context, db *sqlx.DB, startTime time.Tim
|
|||
logrus.Warnf("context is cancelled, stop syncing")
|
||||
return ctx.Err()
|
||||
|
||||
case err := <-errC:
|
||||
return err
|
||||
|
||||
default:
|
||||
v, ok := dataCRef.Recv()
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue
Block a user