17 using System.Collections;
18 using System.Collections.Generic;
32 private readonly DateTimeZone _exchangeTimeZone;
33 private readonly List<IEnumerator<BaseData>> _auxDataEnumerators;
34 private readonly IEnumerator<BaseData> _tradeBarAggregator;
45 _timeProvider = timeProvider;
46 _exchangeTimeZone = exchangeTimeZone;
47 _auxDataEnumerators = auxDataEnumerators;
48 _tradeBarAggregator = tradeBarAggregator;
59 var frontierUtc = _timeProvider.GetUtcNow();
62 if (DataPointEmitted(frontierUtc))
66 for (var i = 0; i < _auxDataEnumerators.Count; i++)
68 if (_auxDataEnumerators[i].
Current ==
null)
70 _auxDataEnumerators[i].MoveNext();
73 if (_tradeBarAggregator.Current ==
null) _tradeBarAggregator.MoveNext();
76 if (DataPointEmitted(frontierUtc))
92 foreach (var auxDataEnumerator
in _auxDataEnumerators)
94 auxDataEnumerator.Reset();
96 _tradeBarAggregator.Reset();
109 object IEnumerator.Current =>
Current;
116 foreach (var auxDataEnumerator
in _auxDataEnumerators)
118 auxDataEnumerator.DisposeSafely();
120 _tradeBarAggregator.DisposeSafely();
123 private bool DataPointEmitted(DateTime frontierUtc)
126 IEnumerator<BaseData> auxDataEnumerator =
null;
127 for (var i = 0; i < _auxDataEnumerators.Count; i++)
129 var currentEnum = _auxDataEnumerators[i];
130 if (currentEnum.Current !=
null)
132 if (auxDataEnumerator ==
null)
134 auxDataEnumerator = currentEnum;
138 auxDataEnumerator = auxDataEnumerator.Current.EndTime > currentEnum.Current.EndTime ? currentEnum : auxDataEnumerator;
144 if (auxDataEnumerator?.
Current !=
null && _tradeBarAggregator.Current !=
null)
146 var auxDataEndTime = auxDataEnumerator.Current.EndTime.ConvertToUtc(_exchangeTimeZone);
147 var tradeBarEndTime = _tradeBarAggregator.Current.EndTime.ConvertToUtc(_exchangeTimeZone);
148 if (auxDataEndTime < tradeBarEndTime)
150 if (auxDataEndTime <= frontierUtc)
152 Current = auxDataEnumerator.Current;
153 auxDataEnumerator.MoveNext();
159 if (tradeBarEndTime <= frontierUtc)
161 Current = _tradeBarAggregator.Current;
162 _tradeBarAggregator.MoveNext();
167 else if (auxDataEnumerator?.
Current !=
null)
169 var auxDataEndTime = auxDataEnumerator.Current.
EndTime.ConvertToUtc(_exchangeTimeZone);
170 if (auxDataEndTime <= frontierUtc)
172 Current = auxDataEnumerator.Current;
173 auxDataEnumerator.MoveNext();
177 else if (_tradeBarAggregator.Current !=
null)
179 var tradeBarEndTime = _tradeBarAggregator.Current.
EndTime.ConvertToUtc(_exchangeTimeZone);
180 if (tradeBarEndTime <= frontierUtc)
182 Current = _tradeBarAggregator.Current;
183 _tradeBarAggregator.MoveNext();