21 using System.Collections.Generic;
38 : base(securities, timeZone, marketHoursDatabase)
55 return dates.Select(date =>
94 return At(
new TimeSpan(hour, minute, second),
TimeZone);
106 return At(
new TimeSpan(hour, minute, 0), timeZone);
117 public ITimeRule At(
int hour,
int minute,
int second, DateTimeZone timeZone)
119 return At(
new TimeSpan(hour, minute, second), timeZone);
130 var name =
string.Join(
",", timeOfDay.TotalHours.ToStringInvariant(
"0.##"));
131 Func<IEnumerable<DateTime>, IEnumerable<DateTime>> applicator = dates =>
133 let localEventTime = date + timeOfDay
134 let utcEventTime = localEventTime.ConvertToUtc(timeZone)
147 if (interval <= TimeSpan.Zero)
149 throw new ArgumentException(
"TimeRules.Every(): time span interval can not be zero or less");
151 var name = Invariant($
"Every {interval.TotalMinutes:0.##} min");
152 Func<IEnumerable<DateTime>, IEnumerable<DateTime>> applicator = dates => EveryIntervalIterator(dates, interval,
TimeZone);
165 return AfterMarketOpen(symbol, minutesBeforeOpen * (-1), extendedMarketOpen);
177 var type = extendedMarketOpen ?
"ExtendedMarketOpen" :
"MarketOpen";
178 var afterOrBefore = minutesAfterOpen > 0 ?
"after" :
"before";
179 var name = Invariant($
"{symbol}: {Math.Abs(minutesAfterOpen):0.##} min {afterOrBefore} {type}");
182 var timeAfterOpen = TimeSpan.FromMinutes(minutesAfterOpen);
183 Func<IEnumerable<DateTime>, IEnumerable<DateTime>> applicator = dates =>
185 let marketOpen = exchangeHours.GetNextMarketOpen(date, extendedMarketOpen)
187 where exchangeHours.IsDateOpen(date, extendedMarketOpen) && marketOpen.Date == date.Date
188 let localEventTime = marketOpen + timeAfterOpen
189 let utcEventTime = localEventTime.ConvertToUtc(exchangeHours.TimeZone)
216 var type = extendedMarketClose ?
"ExtendedMarketClose" :
"MarketClose";
217 var afterOrBefore = minutesBeforeClose > 0 ?
"before" :
"after";
218 var name = Invariant($
"{symbol}: {Math.Abs(minutesBeforeClose):0.##} min {afterOrBefore} {type}");
221 var timeBeforeClose = TimeSpan.FromMinutes(minutesBeforeClose);
222 Func<IEnumerable<DateTime>, IEnumerable<DateTime>> applicator = dates =>
224 let marketClose = exchangeHours.GetNextMarketClose(date, extendedMarketClose)
226 where exchangeHours.IsDateOpen(date, extendedMarketClose) && marketClose.Date == date.Date
227 let localEventTime = marketClose - timeBeforeClose
228 let utcEventTime = localEventTime.ConvertToUtc(exchangeHours.TimeZone)
240 private static IEnumerable<DateTime> EveryIntervalIterator(IEnumerable<DateTime> dates, TimeSpan interval, DateTimeZone timeZone)
242 if (interval <= TimeSpan.Zero)
244 throw new ArgumentException(
"TimeRules.EveryIntervalIterator(): time span interval can not be zero or less");
246 foreach (var date
in dates)
248 for (var time = TimeSpan.Zero; time <
Time.
OneDay; time += interval)
250 yield
return (date + time).ConvertToUtc(timeZone);