private TradingDayInfo GetTradingDayInfo(IEnumerable <ScheduleSettings> scheduleSettings, BrokerSettingsContract brokerSettings, DateTime currentDateTime) { var compiledSchedule = CompileSchedule(scheduleSettings, currentDateTime); var currentInterval = compiledSchedule .Where(x => IsBetween(currentDateTime, x.Start, x.End)) .OrderByDescending(x => x.Schedule.Rank) .FirstOrDefault(); var isEnabled = currentInterval.Enabled(); var lastTradingDay = GetPreviousTradingDay(compiledSchedule, currentInterval, currentDateTime); var nextTradingDay = GetNextTradingDay(compiledSchedule, currentInterval, currentDateTime, lastTradingDay); var isBusinessDay = !brokerSettings.Weekends.Contains(currentDateTime.DayOfWeek) && !brokerSettings.Holidays.Select(x => x.Date).Contains(currentDateTime.Date); var result = new TradingDayInfo { IsTradingEnabled = isEnabled, LastTradingDay = lastTradingDay, NextTradingDayStart = nextTradingDay, IsBusinessDay = isBusinessDay }; return(result); }
private static TradingDayInfo GetTradingDayInfo( IEnumerable <ScheduleSettings> scheduleSettings, DateTime currentDateTime) { var compiledSchedule = CompileSchedule(scheduleSettings, currentDateTime); var currentInterval = compiledSchedule .Where(x => IsBetween(currentDateTime, x.Start, x.End)) .OrderByDescending(x => x.Schedule.Rank) .FirstOrDefault(); var isEnabled = currentInterval.Enabled(); var lastTradingDay = GetPreviousTradingDay(compiledSchedule, currentInterval, currentDateTime); var nextTradingDay = GetNextTradingDay(compiledSchedule, currentInterval, currentDateTime, lastTradingDay); var result = new TradingDayInfo { IsTradingEnabled = isEnabled, LastTradingDay = lastTradingDay, NextTradingDayStart = nextTradingDay }; return(result); }