/// <summary> /// 判断交易日期,有日盘就被看作是交易日。注意周六不是trading day,但周六凌晨是有交易的 /// </summary> /// <param name="date"></param> /// <returns></returns> public static bool IsTradeDay(Date date) { if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) { return(false); } return(!HolidayDao.IsHoliday(date)); }
/// <summary> /// 根据开收盘时间判断是否交易时间 /// 特别说明:已经在行情里使用,谨慎修改 /// 作者:jincheng /// 修改时间:2017年8月11日 14:19:15 /// </summary> /// <param name="time"></param> /// <param name="symbol"></param> /// <param name="defaultValue">出错时的默认值</param> /// <returns></returns> private static bool IsTradingTime(DateTime time, List <TradeTimeRange> timeRangeList, bool defaultValue = true) { var nowHhmmss = time.GetHHMMSS(); var nightTradeTimeRange = timeRangeList.FirstOrDefault(p => p.BeginTime >= NightBeginTime); if (time.DayOfWeek == DayOfWeek.Saturday) { if (nightTradeTimeRange == null) { return(false); } if (nowHhmmss > nightTradeTimeRange.EndTime) { return(false); } } if (time.DayOfWeek == DayOfWeek.Sunday) { return(false); } if (HolidayDao.IsHoliday(time.ToDate())) { return(false); } if (nowHhmmss >= 210000) { var isHolidayNight = HolidayDao.IsHolidayNight(time.ToDate()); if (isHolidayNight) { return(false); } } if (nowHhmmss >= 0 && nowHhmmss <= 30000) //节假日前一夜及第二天凌晨 无交易。节假日前夜,且第二天非法定节假日如:2017.09.30 { var isHolidayNight = HolidayDao.IsHolidayNight(time.AddDays(-1).ToDate()); if (isHolidayNight) { return(false); } } if (timeRangeList == null || timeRangeList.Count <= 0) { return(defaultValue); } var hhmmss = time.GetHHMMSS(); //星期6需要特殊处理 if (time.DayOfWeek == DayOfWeek.Saturday) { if (hhmmss >= 210000) { return(false); } return(timeRangeList.Exists( e => e.BeginTime >= NightBeginTime && e.EndTime < e.BeginTime && (hhmmss <= e.EndTime || hhmmss >= e.BeginTime))); } if (time.DayOfWeek == DayOfWeek.Monday) { var startTime = timeRangeList.Where(e => e.BeginTime < NightBeginTime).OrderBy(p => p.BeginTime).FirstOrDefault(); if (startTime != null) { if (hhmmss < startTime.BeginTime) { return(false); } } } var isDay = timeRangeList.Exists(e => e.BeginTime < NightBeginTime && (e.EndTime > e.BeginTime && hhmmss >= e.BeginTime && hhmmss <= e.EndTime)); //白天 if (isDay) { return(true); } var isNight = timeRangeList.Exists(e => e.BeginTime >= NightBeginTime && ((e.EndTime < e.BeginTime && (hhmmss <= e.EndTime || hhmmss >= e.BeginTime)) || (e.EndTime > e.BeginTime && hhmmss >= e.BeginTime && hhmmss <= e.EndTime)));//夜盘 if (isNight) { return(true); } return(false); }