/// <summary>
 /// 港股改单校验
 /// </summary>
 /// <param name="request">改单请求对象</param>
 /// <param name="entrusInfo">原委托单对象</param>
 /// <param name="errMsg">异常信息</param>
 /// <returns>返回检验是否成功</returns>
 public static bool Validate(HKModifyOrderRequest request, ReckoningCounter.Entity.Model.HK.HK_TodayEntrustInfo entrusInfo, ref string errMsg)
 {
     try
     {
         bool result = McValidater.GetInstance().ValidateHKModifyOrderRule(request, entrusInfo, ref errMsg);
         return(result);
     }
     catch (Exception ex)
     {
         LogHelper.WriteError(ex.ToString(), ex);
         return(false);
     }
 }
        /// <summary>
        /// 期货校验
        /// </summary>
        /// <param name="request">期货合约</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns>校验成功失败结果</returns>
        public static bool Validate(MercantileFuturesOrderRequest request, ref string errMsg)
        {
            try
            {
                //内部校验
                LocalFutureOpenValidater localFutureOpenValidater = new LocalFutureOpenValidater(request);
                bool result = localFutureOpenValidater.Check(out errMsg, Types.BreedClassTypeEnum.CommodityFuture);

                //外部校验
                if (result)
                {
                    result = McValidater.GetInstance().ValidateFutureTradeRule(request, ref errMsg);
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.ToString(), ex);
                return(false);
            }
        }
        /// <summary>
        /// 股票校验
        /// </summary>
        /// <param name="request">股票委托</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns>校验成功失败结果</returns>
        public static bool Validate(StockOrderRequest request, ref string errMsg)
        {
            try
            {
                //内部校验
                LocalStockValidater local = new LocalStockValidater(request);
                bool result = local.Check(out errMsg);

                //外部校验
                if (result)
                {
                    result = McValidater.GetInstance().ValidateStockTradeRule(request, ref errMsg);
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.ToString(), ex);
                return(false);
            }
        }
        public OrderResponse Process(HKModifyOrderRequest hkOrder)
        {
            LogHelper.WriteDebug("M——>ModifyOrderProcessor.Process接收改单入口" + hkOrder);

            bool          canModifyOrder  = false;
            OrderResponse orResult        = new OrderResponse();
            string        strErrorMessage = "";

            //hkOrder.ID = HKCommonLogic.BuildHKOrderNo();
            hkOrder.ID = Guid.NewGuid().ToString();

            #region 原始单位及成交量转换

            var            code        = hkOrder.Code;
            var            oriUnitType = hkOrder.OrderUnitType;
            decimal        scale;
            Types.UnitType matchUnitType;

            bool canConvert = OrderAccepter.ConvertUnitType(Types.BreedClassTypeEnum.HKStock, code, oriUnitType, out scale, out matchUnitType);
            if (!canConvert)
            {
                strErrorMessage = @"GT-2450:[港股委托]无法进行行情单位转换.";
                goto EndProcess;
            }
            LogHelper.WriteDebug("委托单:" + hkOrder.EntrustNubmer + "当前改单获取到的转换倍数为: " + scale);
            hkOrder.OrderUnitType = matchUnitType;
            hkOrder.OrderAmount   = hkOrder.OrderAmount * (float)scale;

            #endregion

            //记录改单操作记录数据
            bool canSave = HKDataAccess.AddHKModifyOrderRequest(hkOrder);
            if (!canSave)
            {
                strErrorMessage = @"GT-2451:[港股改单委托]无法保持改单委托,请查看错误日志.";
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);

                goto EndProcess;
            }

            #region 校验

            if ((string.IsNullOrEmpty(hkOrder.TraderId) && string.IsNullOrEmpty(hkOrder.FundAccountId)))
            {
                strErrorMessage = @"GT-2452:[港股改单委托]交易员ID或资金帐户无效.";
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);

                goto EndProcess;
            }

            //柜台委托时间判断
            if (!ValidateCenter.IsCountTradingTime(Types.BreedClassTypeEnum.HKStock, hkOrder.Code, ref strErrorMessage))
            {
                LogHelper.WriteInfo("ModifyOrderProcessor.Process" + strErrorMessage);
                string oriMsg = "当前时间不接受委托";
                if (strErrorMessage.Length > 0)
                {
                    oriMsg = strErrorMessage;
                }

                strErrorMessage = @"GT-2453:[港股改单委托]" + oriMsg;
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);
                goto EndProcess;
            }

            HK_TodayEntrustInfo tet = HKDataAccess.GetTodayEntrustTable(hkOrder.EntrustNubmer);
            if (tet == null)
            {
                strErrorMessage = "GT-2454:[港股改单委托]无委托对象信息";
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);

                goto EndProcess;
            }

            if ((float)tet.EntrustPrice == hkOrder.OrderPrice && tet.EntrustAmount == (int)hkOrder.OrderAmount)
            {
                strErrorMessage = "GT-2455:[港股改单委托]无效改单,改单量、改单价与原始委托相同";
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);

                goto EndProcess;
            }

            //港股改单规则检验,这里有些与真实下单有些重复,但这样可以提高改单的成功率
            if (!McValidater.GetInstance().ValidateHKModifyOrderRule(hkOrder, tet, ref strErrorMessage))
            {
                LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);
                goto EndProcess;
            }

            #endregion

            //未报
            if (tet.OrderStatusID == (int)Entity.Contants.Types.OrderStateType.DOSUnRequired)
            {
                ProcessType1(hkOrder);
                canModifyOrder = true;
                goto EndProcess;
            }

            #region 已报、部成

            if (tet.OrderStatusID == (int)Entity.Contants.Types.OrderStateType.DOSIsRequired ||
                tet.OrderStatusID == (int)Entity.Contants.Types.OrderStateType.DOSPartDealed)
            {
                //如果不在交易时间内,那么直接到缓存中删除原来的委托,生成新委托
                if (!ValidateCenter.IsMatchTradingTime(Types.BreedClassTypeEnum.HKStock, hkOrder.Code))
                {
                    strErrorMessage = "GT-2456:[港股改单委托]不在交易时间内";
                    LogHelper.WriteInfo(strErrorMessage + "," + hkOrder);

                    goto EndProcess;
                }

                if ((decimal)hkOrder.OrderPrice == tet.EntrustPrice && hkOrder.OrderAmount < tet.EntrustAmount)
                {
                    ProcessType2(hkOrder);
                    canModifyOrder = true;
                }
                else
                {
                    ProcessType3(hkOrder);
                    canModifyOrder = true;
                    goto EndProcess;
                }
            }

            #endregion

EndProcess:
            //结束
            if (canModifyOrder)
            {
                hkOrder.ModifyOrderDateTime = DateTime.Now;
                orResult.OrderDatetime      = DateTime.Now;
            }
            else
            {
                int  type            = 0;
                bool canGetErrorCode = Utils.GetErrorCode(strErrorMessage, out type);
                if (canGetErrorCode)
                {
                    orResult.ErrorType = type;
                }

                hkOrder.Message       = strErrorMessage;
                orResult.OrderMessage = strErrorMessage;
            }

            //更新改单委托
            HKDataAccess.UpdateModifyOrderRequest(hkOrder);

            orResult.IsSuccess = canModifyOrder;
            orResult.OrderId   = hkOrder.ID;
            return(orResult);
        }
 /// <summary>
 /// 根据商品代码,商品类型获取某一期货商品的费用计算公式
 /// </summary>
 /// <param name="code">商品代码</param>
 /// <returns>FutureRuleContainer</returns>
 public static FutureRuleContainer GetFutureRuleContainerByCode(string code)
 {
     return(McValidater.GetInstance().GetFutureRuleContainerByCode(code));
 }