public List <Quotation> GetLastDayQuotations(DateTime dateTime) { var previousDay = dateTime.DayOfWeek == DayOfWeek.Sunday ? dateTime.AddDays(-2).Date : (dateTime.DayOfWeek == DayOfWeek.Monday ? dateTime.AddDays(-3) : dateTime.AddDays(-1)); return(Quotations.Where(x => x.Time.Day == previousDay.Date.Day).ToList()); }
public Quotation GetDayQuotation(DateTime dateTime, int daysAgo) { var previousDay = dateTime.DayOfWeek == DayOfWeek.Sunday ? dateTime.AddDays(-1 - daysAgo).Date : (dateTime.DayOfWeek == DayOfWeek.Monday ? dateTime.AddDays(-2 - daysAgo) : dateTime.AddDays(0 - daysAgo)); if (!Interval.Equals(Inteval.D1)) { var quotationByDay = Quotations.Where(x => x.Time.Date == previousDay.Date); if (!quotationByDay.Any()) { throw new DomainException("There is no previous quotations"); } var open = quotationByDay.OrderBy(x => x.Time).FirstOrDefault().Open; var high = quotationByDay.Max(x => x.High); var low = quotationByDay.Min(x => x.Low); var close = quotationByDay.OrderByDescending(x => x.Time).FirstOrDefault().Close; var volume = quotationByDay.Sum(x => x.Volume); return(new Quotation(previousDay.Date, open, low, high, close, volume)); } return(Quotations.FirstOrDefault(x => x.Time.Date == previousDay.Date) ?? throw new DomainException("There is no previous day quotation.")); }