/// <summary> /// 今日期货是否可以执行清算(内部即检查当前时间与记录比较前一日是否请算完成) /// </summary> /// <param name="faultRecoveryTime">能够清算的时间</param> /// <param name="errMsg">查询返回异常或者提示信息</param> /// <returns></returns> public static bool IsFutureTodayReckoning(out DateTime faultRecoveryTime, out string errMsg) { errMsg = ""; //要执行清算的日期 faultRecoveryTime = DateTime.Now; string dateTime = StatusTableChecker.GetFutureReckoningHasDone(); if (string.IsNullOrEmpty(dateTime)) { errMsg = "清算状态表无记录,可以执行清算!"; return(true); } DateTime lastDate = DateTime.Parse(dateTime); if (lastDate.Day == DateTime.Now.Day) { errMsg = "今日已经执行清算完成!"; return(false); } else if (lastDate.Date.AddDays(1).Date == DateTime.Now.Date) { //DateTime nowDate = DateTime.Now; //DateTime firstBeginTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, ScheduleManager.FirstBeginTime.Hour, ScheduleManager.FirstBeginTime.Minute, ScheduleManager.FirstBeginTime.Second); //DateTime lastEndTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, ScheduleManager.LastEndTime.Hour, ScheduleManager.LastEndTime.Minute, ScheduleManager.LastEndTime.Second); //if (nowDate >= firstBeginTime && nowDate <= lastEndTime) //{ // errMsg = "今日还没有到清算的时间,请稍后再试!"; // return false; //} return(true); } faultRecoveryTime = lastDate; bool isTradeDate = false; while (!isTradeDate) { //判断是否是星期六星期日,如果是向后推清算日期 for (int i = 1; i <= 3; i++) { faultRecoveryTime = faultRecoveryTime.AddDays(i); if (faultRecoveryTime.DayOfWeek == DayOfWeek.Sunday || faultRecoveryTime.DayOfWeek == DayOfWeek.Saturday) { continue; } else { break; } } //获取到要清算的日期再判断是否是非交易日期,如果是再向后推(while) //获取 所有期货的交易所的ID //IList<CM_BourseType> cm_bourseList = MCService.CommonPara.GetAllBourseType(); List <int> cm_bourseList = new List <int>(); //获取所有品种类别 IList <CM_BreedClass> cm_breedClass = MCService.CommonPara.GetAllBreedClass(); //过期不是期货的不用判断 foreach (var item in cm_breedClass) { switch ((Types.BreedClassTypeEnum)item.BreedClassTypeID) { case Types.BreedClassTypeEnum.Stock: break; case Types.BreedClassTypeEnum.CommodityFuture: case Types.BreedClassTypeEnum.StockIndexFuture: if (!cm_bourseList.Contains(item.BourseTypeID.Value)) { cm_bourseList.Add(item.BourseTypeID.Value); } break; case Types.BreedClassTypeEnum.HKStock: break; default: break; } } //要所有交易所都为非交易日时才可以清算 foreach (var item in cm_bourseList) { isTradeDate = MCService.CommonPara.IsTradeDate(item, faultRecoveryTime); if (isTradeDate) { break; } } } if (faultRecoveryTime.Date == DateTime.Now.Date) { return(true); } return(false); }
/// <summary> /// 期货是否要执行期货清算故障恢复 /// </summary> /// <param name="faultRecoveryTime">要执行故障恢复清算的日期</param> /// <param name="errMsg">查询返回异常或者提示信息</param> /// <returns></returns> public static bool IsFutureReckoningFaultRecovery(out DateTime faultRecoveryTime, out string errMsg) { errMsg = ""; //要执行清算的日期 faultRecoveryTime = DateTime.Now; try { string dateTime = StatusTableChecker.GetFutureReckoningHasDone(); if (string.IsNullOrEmpty(dateTime)) { errMsg = "清算状态表记录无法获取,有异常请检查!"; return(false); } DateTime lastDate = DateTime.Parse(dateTime); if (lastDate.Day == DateTime.Now.Day) { errMsg = "今日已经执行清算完成!"; return(false); } else if (lastDate.Date.AddDays(1).Date == DateTime.Now.Date) { DateTime nowDate = DateTime.Now; DateTime firstBeginTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, ScheduleManager.FirstBeginTime.Hour, ScheduleManager.FirstBeginTime.Minute, ScheduleManager.FirstBeginTime.Second); DateTime lastEndTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, ScheduleManager.LastEndTime.Hour, ScheduleManager.LastEndTime.Minute, ScheduleManager.LastEndTime.Second); if (nowDate >= firstBeginTime && nowDate <= lastEndTime) { errMsg = "今日还没有到清算的时间,请稍后再试!"; return(false); } //如果当前时间是零晨到开市之前的也应该不用执行清算 if (nowDate >= DateTime.Now.Date && nowDate <= firstBeginTime) { errMsg = "今日还没有到清算的时间,请稍后再试!"; return(false); } //如果不在交易时间内了,还没有清算完成那么返回要执行清算 //这里判断已经保证是在当前了 //这里再加二十分钟是因为清算时要时间(设置二十分钟因为测试过有一万用户的时间期货清算大约要五分钟) if (nowDate > lastEndTime.AddMinutes(20)) { return(true); } } //处理星期五清算不成功,然后星期一处理的手动执行清算后 #region update 2010-03-17 old code //bool isTradeDate = false; //while (!isTradeDate) //{ // //判断是否是星期六星期日,如果是向后推清算日期 // for (int i = 1; i <= 3; i++) // { // faultRecoveryTime = lastDate.AddDays(i); // if (faultRecoveryTime.DayOfWeek == DayOfWeek.Sunday || faultRecoveryTime.DayOfWeek == DayOfWeek.Saturday) // { // continue; // } // else // { // break; // } // } // //获取到要清算的日期再判断是否是非交易日期,如果是再向后推 // IList<CM_BourseType> cm_bourseList = MCService.CommonPara.GetAllBourseType(); // foreach (var item in cm_bourseList) // { // isTradeDate = MCService.CommonPara.IsTradeDate(item.BourseTypeID, faultRecoveryTime); // if (!isTradeDate) // { // break; // } // } //} #endregion #region 2010-03-17 new //这里返回的,我们只要补完当前日期的前一天的记录即可 bool isTradeDate = false; while (!isTradeDate) { #region 判断是否是星期六星期日,如果是向后推清算日期 //判断是否是星期六星期日,如果是向后推清算日期 for (int i = 1; i <= 3; i++) { faultRecoveryTime = faultRecoveryTime.AddDays(-1); //向前推日期,如果是星期六星期日再向前推 if (faultRecoveryTime.DayOfWeek == DayOfWeek.Sunday || faultRecoveryTime.DayOfWeek == DayOfWeek.Saturday) { continue; } else { break; } } #endregion //如果向前推到最后还是和原来的清算日期相等那么就不用再清算 if (faultRecoveryTime.ToShortDateString() == lastDate.ToShortDateString()) { errMsg = "今日向前再推算日期与之前正常清算的日期相符,不用再清算!"; return(false); } #region 过期不是期货的不用判断 //获取到要清算的日期再判断是否是非交易日期,如果是再向后推(while) //获取 所有期货的交易所的ID //IList<CM_BourseType> cm_bourseList = MCService.CommonPara.GetAllBourseType(); List <int> cm_bourseList = new List <int>(); //获取所有品种类别 IList <CM_BreedClass> cm_breedClass = MCService.CommonPara.GetAllBreedClass(); //过期不是期货的不用判断 foreach (var item in cm_breedClass) { switch ((Types.BreedClassTypeEnum)item.BreedClassTypeID) { case Types.BreedClassTypeEnum.Stock: break; case Types.BreedClassTypeEnum.CommodityFuture: case Types.BreedClassTypeEnum.StockIndexFuture: if (!cm_bourseList.Contains(item.BourseTypeID.Value)) { cm_bourseList.Add(item.BourseTypeID.Value); } break; case Types.BreedClassTypeEnum.HKStock: break; default: break; } } #endregion //要每个交易所都是非交易时间才可以进行清算故障恢复 foreach (var item in cm_bourseList) { isTradeDate = MCService.CommonPara.IsTradeDate(item, faultRecoveryTime); if (isTradeDate) { #region 再处理向前推日期,解决星期五清算不成功,星期一进行清算时再获取清算的日志返回故障恢复清算错误,即把日期再返回未清算紧跟的非交易日后 DateTime requestDate = faultRecoveryTime; //只处理星期六星期日 for (int i = 1; i <= 3; i++) { requestDate = requestDate.AddDays(1); if (requestDate.DayOfWeek == DayOfWeek.Sunday || requestDate.DayOfWeek == DayOfWeek.Saturday) { faultRecoveryTime = requestDate; //如果当前时间是星期六那么就直接退出用星期六即可 if (requestDate.Date == DateTime.Now.Date) { break; } continue; } else { break; } } #endregion return(true); } } } #endregion } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); } return(true); }