21 using System.Collections.Generic;
22 using System.Collections.Specialized;
35 private readonly TimeSpan _interval;
36 private readonly HashSet<SubscriptionDataConfig> _subscriptionDataConfigs =
new HashSet<SubscriptionDataConfig>();
37 private readonly HashSet<Symbol> _symbols =
new HashSet<Symbol>();
40 private readonly HashSet<SubscriptionDataConfig> _pendingRemovedConfigs =
new HashSet<SubscriptionDataConfig>();
41 private readonly Func<DateTime, IEnumerable<Symbol>> _selector;
42 private readonly
object _lock =
new ();
54 get {
return _interval; }
68 _symbols = symbols.ToHashSet();
74 return _subscriptionDataConfigs.Select(x => x.Symbol).Union(_symbols).ToHashSet();
109 var ticker = $
"qc-universe-userdefined-{market.ToLowerInvariant()}-{securityType}";
124 added = _symbols.Add(symbol);
129 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, symbol));
146 added = _subscriptionDataConfigs.Add(subscriptionDataConfig);
151 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, subscriptionDataConfig.
Symbol));
164 if (RemoveAndKeepTrack(symbol))
166 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, symbol));
180 return _selector(utcTime);
190 var localStartTime = startTimeUtc.ConvertFromUtc(exchangeHours.TimeZone);
191 var localEndTime = endTimeUtc.ConvertFromUtc(exchangeHours.TimeZone);
198 yield
return dateTime;
203 yield
return dateTime;
226 DateTime currentTimeUtc,
227 DateTime maximumEndTimeUtc,
230 List<SubscriptionDataConfig> result;
233 result = _subscriptionDataConfigs.Where(x => x.Symbol == security.
Symbol).ToList();
236 result = _pendingRemovedConfigs.Where(x => x.Symbol == security.
Symbol).ToList();
239 _pendingRemovedConfigs.RemoveWhere(x => x.Symbol == security.
Symbol);
243 result = base.GetSubscriptionRequests(security, currentTimeUtc, maximumEndTimeUtc, subscriptionService).Select(x => x.Configuration).ToList();
245 _subscriptionDataConfigs.UnionWith(result);
252 configuration: config,
253 startTimeUtc: currentTimeUtc,
254 endTimeUtc: maximumEndTimeUtc));
264 internal override bool RemoveMember(DateTime utcTime,
Security security)
266 if (base.RemoveMember(utcTime, security))
268 RemoveAndKeepTrack(security.
Symbol);
274 private bool RemoveAndKeepTrack(
Symbol symbol)
278 var toBeRemoved = _subscriptionDataConfigs.Where(x => x.Symbol == symbol).ToList();
279 var removedSymbol = _symbols.Remove(symbol);
281 if (removedSymbol || toBeRemoved.Any())
283 _subscriptionDataConfigs.RemoveWhere(x => x.Symbol == symbol);
284 _pendingRemovedConfigs.UnionWith(toBeRemoved);