service/backtest: filter klines that will be closed in the future

This commit is contained in:
c9s 2022-08-19 17:55:48 +08:00
parent 49728622bc
commit 5d85ceeec4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -37,6 +37,7 @@ func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange type
_, _ = s.DB.Exec("PRAGMA synchronous = NORMAL")
}
now := time.Now()
tasks := []SyncTask{
{
Type: types.KLine{},
@ -46,7 +47,16 @@ func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange type
},
Filter: func(obj interface{}) bool {
k := obj.(types.KLine)
return !k.EndTime.Before(k.StartTime.Time().Add(k.Interval.Duration() - time.Second))
if k.EndTime.Before(k.StartTime.Time().Add(k.Interval.Duration() - time.Second)) {
return false
}
// Filter klines that has the endTime closed in the future
if k.EndTime.After(now) {
return false
}
return true
},
ID: func(obj interface{}) string {
kline := obj.(types.KLine)