|
|
|
|
@ -266,6 +266,13 @@ func (b *SigStrategyBacktester) multiInstanceIntervalSeries(ctx context.Context,
|
|
|
|
|
syncCh := make(chan int64) |
|
|
|
|
syncChans = append(syncChans, syncCh) |
|
|
|
|
go func(isr *pb.SeriesRange, kSeries *types.KlineSeries, syncCh chan int64) { |
|
|
|
|
defer func() { |
|
|
|
|
if e := recover(); e != nil { |
|
|
|
|
zlog.Errorf("fetch interval history panic: inst=%s(%s) interval=%s, err=%v", sr.InstId, sr.Exchange, isr.Interval, e) |
|
|
|
|
err = fmt.Errorf("panic: %v", e) |
|
|
|
|
close(stopCh) |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
interval := types.Interval(isr.Interval) |
|
|
|
|
intervalAdder := types.SupportedIntervals[interval] |
|
|
|
|
driverTs := int64(0) |
|
|
|
|
@ -311,7 +318,7 @@ func (b *SigStrategyBacktester) multiInstanceIntervalSeries(ctx context.Context,
|
|
|
|
|
}) |
|
|
|
|
zlog.Debugf("other sr finish with: %s(%s), %v, last=%d", isr.InstId, isr.Interval, err1, intervalAdder(kSeries.MustGet(0).Ts, 1)) |
|
|
|
|
if err1 == nil { |
|
|
|
|
syncCh <- -1 // 通知更新完毕, 后续不再更新
|
|
|
|
|
close(syncCh) // k线数据拉取完毕, 后续不再更新
|
|
|
|
|
} else if err1 != errStop { |
|
|
|
|
zlog.Errorf("fetch interval history error: inst=%s(%s) interval=%s, err=%v", sr.InstId, sr.Exchange, interval, err1) |
|
|
|
|
err = err1 |
|
|
|
|
@ -332,15 +339,19 @@ func (b *SigStrategyBacktester) multiInstanceIntervalSeries(ctx context.Context,
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
driverTS := driverIntervalAdder(k.Ts, 1) |
|
|
|
|
for i, syncCh := range syncChans { |
|
|
|
|
for _, syncCh := range syncChans { |
|
|
|
|
if syncCh == nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
syncCh <- driverTS // 通知其他周期更新到主周期时间
|
|
|
|
|
} |
|
|
|
|
for i, syncCh := range syncChans { |
|
|
|
|
if syncCh == nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
select { |
|
|
|
|
case sig := <-syncCh: // 等待该周期更新完毕
|
|
|
|
|
if sig == -1 { |
|
|
|
|
// 后续不再更新
|
|
|
|
|
case _, ok := <-syncCh: // 等待其他周期更新完毕
|
|
|
|
|
if !ok { |
|
|
|
|
syncChans[i] = nil |
|
|
|
|
} |
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|