service/backtest: check and filter kline by its endTime

This commit is contained in:
c9s 2022-08-19 17:28:55 +08:00
parent 834487d568
commit 5e1e0c7661
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 6 additions and 0 deletions

View File

@ -44,6 +44,10 @@ func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange type
Time: func(obj interface{}) time.Time {
return obj.(types.KLine).StartTime.Time()
},
Filter: func(obj interface{}) bool {
k := obj.(types.KLine)
return !k.EndTime.Before(k.StartTime.Time().Add(k.Interval.Duration() - time.Millisecond))
},
ID: func(obj interface{}) string {
kline := obj.(types.KLine)
return strconv.FormatInt(kline.StartTime.UnixMilli(), 10)

View File

@ -35,6 +35,8 @@ type SyncTask struct {
OnLoad func(objs interface{})
// Filter is an optional field, which is used for filtering the remote records
// Return true to keep the record,
// Return false to filter the record.
Filter func(obj interface{}) bool
// BatchQuery is used for querying remote records.