25 using System.Collections.Generic;
26 using Timer = System.Timers.Timer;
37 private readonly Random _random =
new Random();
38 private int _dataPointsPerSecondPerSymbol;
40 private readonly Timer _timer;
46 private readonly Dictionary<Symbol, TimeZoneOffsetProvider> _symbolExchangeTimeZones;
68 _aggregator = dataAggregator;
69 _dataPointsPerSecondPerSymbol = dataPointsPerSecondPerSymbol;
74 _symbolExchangeTimeZones =
new Dictionary<Symbol, TimeZoneOffsetProvider>();
76 _subscriptionManager.SubscribeImpl += (s, t) =>
true;
77 _subscriptionManager.UnsubscribeImpl += (s, t) =>
true;
87 var lastTime = DateTime.UtcNow;
88 _timer.Elapsed += (sender, args) =>
90 var elapsed = (DateTime.UtcNow - lastTime);
91 var ticksPerSecond = (_count - lastCount)/elapsed.TotalSeconds;
92 Log.
Trace(
"TICKS PER SECOND:: " + ticksPerSecond.ToStringInvariant(
"000000.0") +
" ITEMS IN QUEUE:: " + 0);
94 lastTime = DateTime.UtcNow;
100 catch (ObjectDisposedException)
115 var enumerator = _aggregator.Add(dataConfig, newDataAvailableHandler);
116 _subscriptionManager.Subscribe(dataConfig);
135 _subscriptionManager.Unsubscribe(dataConfig);
136 _aggregator.Remove(dataConfig);
151 _timer.DisposeSafely();
152 _dataCacheProvider.DisposeSafely();
158 private void PopulateQueue()
160 var symbols = _subscriptionManager.GetSubscribedSymbols();
163 foreach (var symbol
in symbols)
165 if (symbol.IsCanonical() || symbol.Contains(
"UNIVERSE"))
169 var offsetProvider = GetTimeZoneOffsetProvider(symbol);
174 for (var i = 0; i < _dataPointsPerSecondPerSymbol; i++)
177 var exchangeTime = offsetProvider.ConvertFromUtc(now);
178 var lastTrade = 100 + (decimal)Math.Abs(Math.Sin(now.TimeOfDay.TotalMilliseconds));
182 _aggregator.Update(
new Tick
188 Quantity = _random.Next(10, (
int)_timer.Interval)
195 var bidPrice = lastTrade * 0.95m;
196 var askPrice = lastTrade * 1.05m;
197 var bidSize = _random.Next(10, (
int) _timer.Interval);
198 var askSize = _random.Next(10, (
int)_timer.Interval);
199 _aggregator.Update(
new Tick(exchangeTime, symbol,
"",
"", bidSize: bidSize, bidPrice: bidPrice, askPrice: askPrice, askSize: askSize));
205 private TimeZoneOffsetProvider GetTimeZoneOffsetProvider(Symbol symbol)
207 TimeZoneOffsetProvider offsetProvider;
208 if (!_symbolExchangeTimeZones.TryGetValue(symbol, out offsetProvider))
211 var exchangeTimeZone = _marketHoursDatabase.GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType).TimeZone;
212 _symbolExchangeTimeZones[symbol] = offsetProvider =
new TimeZoneOffsetProvider(exchangeTimeZone,
TimeProvider.
GetUtcNow(), Time.EndOfTime);
214 return offsetProvider;
224 public IEnumerable<Symbol>
LookupSymbols(
Symbol symbol,
bool includeExpired,
string securityCurrency =
null)
231 foreach (var result
in _optionChainProvider.GetOptionContractList(symbol, DateTime.UtcNow.Date))