23 using System.Collections.Generic;
48 _securities = securities;
65 public override IEnumerable<Slice>
GetHistory(IEnumerable<HistoryRequest> requests, DateTimeZone sliceTimeZone)
67 var configsByDateTime = GetSubscriptionDataConfigByDateTime(requests);
68 var count = configsByDateTime.Count;
71 foreach (var kvp
in configsByDateTime)
73 var utcDateTime = kvp.Key;
74 var configs = kvp.Value;
75 var last = Convert.ToDecimal(100 + 10 * Math.Sin(Math.PI * (360 - count + i) / 180.0));
76 var high = last * 1.005m;
77 var low = last / 1.005m;
79 var packets =
new List<DataFeedPacket>();
81 foreach (var config
in configs)
84 if (!_securities.TryGetValue(config.Symbol, out security))
90 var time = (utcDateTime - period).ConvertFromUtc(config.DataTimeZone);
91 var data =
new TradeBar(time, config.Symbol, last, high, last, last, 1000, period);
92 security.SetMarketPrice(data);
93 packets.Add(
new DataFeedPacket(security, config,
new List<BaseData> { data }));
97 yield
return timeSliceFactory.Create(utcDateTime, packets, _securityChanges,
new Dictionary<Universe, BaseDataCollection>()).Slice;
101 private Dictionary<DateTime, List<SubscriptionDataConfig>> GetSubscriptionDataConfigByDateTime(
102 IEnumerable<HistoryRequest> requests)
104 var dictionary =
new Dictionary<DateTime, List<SubscriptionDataConfig>>();
106 var barSize = requests.Select(x => x.Resolution.ToTimeSpan()).Min();
107 var startUtc = requests.Min(x => x.StartTimeUtc);
108 var endUtc = requests.Max(x => x.EndTimeUtc);
110 for (var utcDateTime = startUtc; utcDateTime < endUtc; utcDateTime += barSize)
112 var subscriptionDataConfig =
new List<SubscriptionDataConfig>();
114 foreach (var request
in requests)
116 var exchange = request.ExchangeHours;
117 var extendedMarket = request.IncludeExtendedMarketHours;
118 var localDateTime = utcDateTime.ConvertFromUtc(exchange.TimeZone);
119 if (!exchange.IsOpen(localDateTime, extendedMarket))
124 var config = request.ToSubscriptionDataConfig();
125 subscriptionDataConfig.Add(config);
128 if (subscriptionDataConfig.Count > 0)
130 dictionary.Add(utcDateTime.Add(barSize), subscriptionDataConfig);