18 using System.Threading;
25 using System.Collections.Generic;
26 using System.Collections.Concurrent;
39 private int _scheduledEventUniqueId;
42 private bool _implementsOnEndOfDaySymbol;
43 private bool _implementsOnEndOfDay;
54 private readonly ConcurrentDictionary<Symbol, ScheduledEvent> _securityOnEndOfDay =
new();
64 public abstract bool IsActive {
get;
protected set; }
72 protected ConcurrentDictionary<ScheduledEvent, int>
ScheduledEvents {
get; } =
new();
106 public abstract void SetTime(DateTime time);
121 ResultHandler = resultHandler;
127 var method =
Algorithm.GetType().GetMethod(
"OnEndOfDay",
new[] { typeof(
Symbol) });
128 var method2 =
Algorithm.GetType().GetMethod(
"OnEndOfDay",
new[] { typeof(
string) });
129 if (method !=
null && method.DeclaringType != typeof(
QCAlgorithm)
130 || method2 !=
null && method2.DeclaringType != typeof(
QCAlgorithm))
132 _implementsOnEndOfDaySymbol =
true;
137 var eodMethod =
Algorithm.GetType().GetMethod(
"OnEndOfDay", Type.EmptyTypes);
138 if (eodMethod !=
null && eodMethod.DeclaringType != typeof(
QCAlgorithm))
140 _implementsOnEndOfDay =
true;
149 _implementsOnEndOfDay = wrapper.IsOnEndOfDayImplemented;
154 throw new ArgumentException(nameof(job.
Language));
158 AddAlgorithmEndOfDayEvent(start: algorithm.
Time, end: algorithm.
EndDate, currentUtcTime: algorithm.
UtcTime);
167 return Interlocked.Increment(ref _scheduledEventUniqueId);
185 [Obsolete(
"This method is deprecated. It will add ScheduledEvents for the deprecated IAlgorithm.OnEndOfDay()")]
186 private void AddAlgorithmEndOfDayEvent(DateTime start, DateTime end, DateTime? currentUtcTime =
null)
189 if (!_implementsOnEndOfDay) {
return; }
191 if (_algorithmOnEndOfDay !=
null)
195 Remove(_algorithmOnEndOfDay);
199 _algorithmOnEndOfDay = ScheduledEventFactory.EveryAlgorithmEndOfDay(
207 Add(_algorithmOnEndOfDay);
219 private void AddSecurityDependentEndOfDayEvents(
220 IEnumerable<Security> securities,
223 DateTime? currentUtcTime =
null)
225 if (_implementsOnEndOfDaySymbol)
228 foreach (var security
in securities)
230 if (!security.IsInternalFeed())
232 var scheduledEvent = ScheduledEventFactory.EverySecurityEndOfDay(
236 _securityOnEndOfDay[security.Symbol] = scheduledEvent;
252 if (_implementsOnEndOfDaySymbol)
262 if (_securityOnEndOfDay.TryRemove(security.Symbol, out scheduledEvent))