Пример #1
0
        /// <summary>
        /// 下单委托操作相关转换信息并缓存相关信息
        /// </summary>
        /// <param name="response"></param>
        /// <param name="request"></param>
        public void ProcessDoOrder(OrderResponse response, MercantileFuturesOrderRequest request)
        {
            QHMessage message = new QHMessage();

            message.BuySell        = request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying ? "买" : "卖";
            message.CapitalAccount = request.FundAccountId;
            message.Code           = request.Code;
            message.EntrustAmount  = request.OrderAmount.ToString();
            message.EntrustNumber  = response.OrderId;
            message.EntrustPrice   = request.OrderPrice.ToString();
            message.EntrustType    = request.OrderWay == TypesOrderPriceType.OPTLimited ? "限价" : "市价";
            message.OrderMessage   = response.OrderMessage;
            message.OrderStatus    = "未报02";
            message.TradeAmount    = "0";
            message.TradeTime      = "";
            message.OpenClose      = Utils.GetFutureOpenCloseType(request.OpenCloseType);

            qhMessageList.Add(message);
            if (!response.IsSuccess)
            {
                message.EntrustNumber = Guid.NewGuid().ToString();
                message.OrderStatus   = "废单06";
            }

            qhMessageCache.Add(message.EntrustNumber, message);

            HasChanged = true;
        }
        public override bool Validate(MercantileFuturesOrderRequest request, ref string strMessage)
        {
            bool result = false;

            string errMsg  = "期货最小变动价位检验失败!";
            string errCode = "GT-1353";

            strMessage = errCode + ":" + errMsg;

            decimal?min = TradeRules.LeastChangePrice;

            if (!min.HasValue)
            {
                return(false);
            }

            decimal minPrice   = min.Value;
            decimal orderPrice = (decimal)request.OrderPrice;

            //是否满足最小变动价位
            if (orderPrice % minPrice == 0)
            {
                result     = true;
                strMessage = "";
            }

            return(result);
        }
        /// <summary>
        /// 获取商品期货交易费用
        /// </summary>
        /// <param name="request">期货委托</param>
        /// <returns>商品期货交易费用结果</returns>
        public static QHCostResult ComputeSPQHCost(MercantileFuturesOrderRequest request)
        {
            int?bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(request.Code);

            QHCostResult result = null;

            if (!bc.HasValue)
            {
                return(null);
            }

            int            breedClassID = bc.Value;
            QH_FutureCosts cost         = MCService.FuturesTradeRules.GetFutureCostsByBreedClassID(breedClassID);

            if (cost == null)
            {
                return(null);
            }

            try
            {
                result = InternalComputeSPQHCost(request, cost);
            }
            catch (Exception ex)
            {
                string      errCode   = "GT-1702";
                string      errMsg    = "无法获取期货货交易费用。";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception);
                throw exception;
            }

            return(result);
        }
Пример #4
0
        //private MercantileFuturesOrderRequest request;

        public LocalFutureOpenValidater(MercantileFuturesOrderRequest request)
        {
            //this.request = request;

            this.traderId = request.TraderId;
            this.code     = request.Code;
            this.buysell  = request.BuySell;
        }
        /// <summary>
        /// 股指期货委托规则检验
        /// </summary>
        /// <param name="request">股指期货委托对象</param>
        /// <param name="errMsg">返回错误检验信息</param>
        /// <returns>是否成功</returns>
        public bool ValidateStockIndexFutureTradeRule(StockIndexFuturesOrderRequest request, ref string errMsg)
        {
            //目前股指期货的校验使用期货的校验
            MercantileFuturesOrderRequest futuresOrderRequest = MCService.GetFuturesOrderRequest(request);


            return(ValidateFutureTradeRule(futuresOrderRequest, ref errMsg));
        }
        public void DoMercantileFuturesOrderTest()
        {
            OrderAccepter target = new OrderAccepter();        // TODO: Initialize to an appropriate value
            MercantileFuturesOrderRequest futuresorder = null; // TODO: Initialize to an appropriate value
            OrderResponse expected = null;                     // TODO: Initialize to an appropriate value
            OrderResponse actual;

            actual = target.DoMercantileFuturesOrder(futuresorder);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <summary>
        /// 获取商品期货交易费用
        /// </summary>
        /// <param name="code">商品期货商品代码</param>
        /// <param name="price">委托价格</param>
        /// <param name="amount">委托数量</param>
        /// <param name="unitType">委托单位类型</param>
        /// <param name="openCloseType">开平仓方向</param>
        /// <returns>商品期货交易费用结果</returns>
        public static QHCostResult ComputeSPQHCost(string code, float price, int amount, Types.UnitType unitType, Entity.Contants.Types.FutureOpenCloseType openCloseType)
        {
            MercantileFuturesOrderRequest request = new MercantileFuturesOrderRequest();

            request.Code          = code;
            request.OrderPrice    = price;
            request.OrderAmount   = amount;
            request.OrderUnitType = unitType;
            request.OpenCloseType = openCloseType;

            return(ComputeSPQHCost(request));
        }
        /// <summary>
        /// 获取交易品种并检验
        /// </summary>
        /// <param name="request">期货委托请求</param>
        /// <param name="iBreed">品种标识</param>
        /// <param name="strMessage">现货检验错误信息</param>
        public bool Validate(MercantileFuturesOrderRequest request, int iBreed, ref string strMessage)
        {
            bool bresult            = false;
            FutureRuleContainer src = GetContainer(iBreed);

            if (src == null)
            {
                src = new FutureRuleContainer(iBreed);
                SetContainer(iBreed, src);
            }

            bresult = src.ValidateAllRules(request, ref strMessage); //调用现货检验总方法
            return(bresult);
        }
        public override bool Validate(MercantileFuturesOrderRequest request, ref string strMessage)
        {
            string errMsg  = "交易员没有此品种的交易权限!";
            string errCode = "GT-1254";

            string tradeID = request.TraderId;

            if (string.IsNullOrEmpty(tradeID))
            {
                strMessage = errCode + ":" + errMsg;
                return(false);
            }

            int userid = 0;

            try
            {
                userid = int.Parse(tradeID.Trim());
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
                strMessage = errCode + ":" + errMsg;
                return(false);
            }

            var rightList = MCService.CommonPara.GetTransactionRightTable(userid);

            if (Utils.IsNullOrEmpty(rightList))
            {
                strMessage = errCode + ":" + errMsg;
                return(false);
            }

            foreach (UM_DealerTradeBreedClass tradeBreedClass in rightList)
            {
                if (!tradeBreedClass.BreedClassID.HasValue)
                {
                    continue;
                }

                if (this.BreedClassID == tradeBreedClass.BreedClassID.Value)
                {
                    return(true);
                }
            }

            strMessage = errCode + ":" + errMsg;
            return(false);
        }
        /// <summary>
        /// 重写实现验证委托量最小倍数方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="strMessage"></param>
        /// <returns></returns>
        public override bool Validate(MercantileFuturesOrderRequest request, ref string strMessage)
        {
            //如果是开仓返回true,直接验证通过,因为开仓的时候已经在内部有处理
            if (request.OpenCloseType == ReckoningCounter.Entity.Contants.Types.FutureOpenCloseType.OpenPosition)
            {
                return(true);
            }

            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByBreedClassID(BreedClassID);

            bool result = true;

            if (breedClass != null && breedClass.BreedClassTypeID.HasValue)
            {
                int breedClassTypeID = breedClass.BreedClassTypeID.Value;
                int breedClassID     = breedClass.BreedClassID;
                //如果是股指期货直接返回true
                if (breedClassTypeID == (int)Types.BreedClassTypeEnum.StockIndexFuture)
                {
                    return(true);
                }

                //如果不是商品期货返回验证不通过
                if (breedClassTypeID != (int)Types.BreedClassTypeEnum.CommodityFuture)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            PositionLimitValueInfo posInfo = MCService.GetPositionLimit(request.Code);

            //如果是最小交割单位的整数倍时
            if (posInfo.IsMinMultiple)
            {
                if (((decimal)request.OrderAmount) % posInfo.MinMultipleValue != 0)
                {
                    LogHelper.WriteDebug("===商品期货验证开仓最小交割单位倍数据: (request.OrderAmount % posInfo.MinMultipleValue)=(" + request.OrderAmount + " % " + posInfo.MinMultipleValue + ")=" + (((decimal)request.OrderAmount) % posInfo.MinMultipleValue));
                    strMessage = "GT-1354:[商品期货委托持久化]开仓持仓检查,持仓限制不是最小交割单位倍数";
                    result     = false;
                }
            }

            return(result);
        }
Пример #11
0
        /// <summary>
        /// 商品期货实体转换为股指期货实体
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static StockIndexFuturesOrderRequest SPQHEntryConversionGZQHEntry(MercantileFuturesOrderRequest model)
        {
            StockIndexFuturesOrderRequest futRequest = new StockIndexFuturesOrderRequest();

            futRequest.BuySell        = model.BuySell;
            futRequest.ChannelID      = model.ChannelID;
            futRequest.Code           = model.Code;
            futRequest.FundAccountId  = model.FundAccountId;
            futRequest.OpenCloseType  = model.OpenCloseType;
            futRequest.OrderAmount    = model.OrderAmount;
            futRequest.OrderPrice     = model.OrderPrice;
            futRequest.OrderUnitType  = model.OrderUnitType;
            futRequest.OrderWay       = model.OrderWay;
            futRequest.PortfoliosId   = model.PortfoliosId;
            futRequest.TraderId       = model.TraderId;
            futRequest.TraderPassword = model.TraderPassword;
            return(futRequest);
        }
        /// <summary>
        /// 期货委托规则检验
        /// </summary>
        /// <param name="request">期货委托对象</param>
        /// <param name="errMsg">返回错误检验信息</param>
        /// <returns>是否成功</returns>
        public bool ValidateFutureTradeRule(MercantileFuturesOrderRequest request, ref string errMsg)
        {
            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code);

            bool result = false;

            if (breedClass != null)
            {
                int breedClassTypeID = breedClass.BreedClassTypeID.Value;
                int breedClassID     = breedClass.BreedClassID;

                //if (breedClassTypeID != (int) Types.BreedClassTypeEnum.CommodityFuture)
                if (breedClassTypeID != (int)Types.BreedClassTypeEnum.CommodityFuture && breedClassTypeID != (int)Types.BreedClassTypeEnum.StockIndexFuture)
                {
                    return(false);
                }

                result = FutureTradingRuleValidater.Validate(request, breedClassID, ref errMsg);
            }

            return(result);
        }
        /// <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>
 /// 检测期货资金表是否正常,因为具体的开平仓由调用方外部校验,所以不再区分开平仓
 /// 统一由LocalFutureOpenValidater进行校验
 /// </summary>
 /// <param name="request"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static bool CheckFuncTable(MercantileFuturesOrderRequest request, ref string errMsg)
 {
     errMsg = "";
     return(false);
 }
 /// <summary>
 /// 检测平仓买卖方向是否与持仓方向相反
 /// </summary>
 /// <param name="request"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static bool CheckCloseDirection(MercantileFuturesOrderRequest request, ref string errMsg)
 {
     errMsg = "";
     return(false);
 }
 /// <summary>
 /// 检测:平仓量<=持仓量
 /// </summary>
 /// <param name="request"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static bool CheckPositionNum(MercantileFuturesOrderRequest request, ref string errMsg)
 {
     errMsg = "";
     return(false);
 }
        public override bool Validate(MercantileFuturesOrderRequest request, ref string strMessage)
        {
            //bool result = false;

            string errMsg  = "期货最小委托量检验失败!";
            string errCode = "GT-1351";

            strMessage = errCode + ":" + errMsg;

            int?consignQuantumID = TradeRules.ConsignQuantumID;

            if (!consignQuantumID.HasValue)
            {
                return(false);
            }

            if (consignQuantum == null)
            {
                consignQuantum = MCService.FuturesTradeRules.GetConsignQuantumByConsignQuantumID(consignQuantumID.Value);
            }

            if (consignQuantum == null)
            {
                return(false);
            }

            if (!consignQuantum.MinConsignQuantum.HasValue)
            {
                return(false);
            }

            Types.UnitType marketUnitType;
            try
            {
                marketUnitType = (Types.UnitType)TradeRules.MarketUnitID;
                ;
            }
            catch
            {
                return(false);
            }

            decimal scale  = MCService.GetTradeUnitScale(request.Code, request.OrderUnitType);
            decimal scale2 = MCService.GetTradeUnitScale(request.Code, marketUnitType);

            var orderAmount = (decimal)request.OrderAmount * scale;
            var minAmount   = consignQuantum.MinConsignQuantum.Value * scale2;

            //进行最小委托量校验
            if (orderAmount < minAmount)
            {
                return(false);
            }
            //最小委托量整数倍验证
            if (orderAmount % minAmount != 0)
            {
                return(false);
            }

            string errMsg2  = "超过当前期货单笔最大委托量!";
            string errCode2 = "GT-1352";

            strMessage = errCode2 + ":" + errMsg2;

            singleRequestQuantityList =
                MCService.FuturesTradeRules.GetSingleRequestQuantityByConsignQuantumID(consignQuantumID.Value);

            QH_SingleRequestQuantity limit_SingleRequestQuantity  = null;
            QH_SingleRequestQuantity market_SingleRequestQuantity = null;

            foreach (QH_SingleRequestQuantity singleRequestQuantity in singleRequestQuantityList)
            {
                if (singleRequestQuantity.ConsignInstructionTypeID.HasValue)
                {
                    int val = singleRequestQuantity.ConsignInstructionTypeID.Value;
                    if (val == (int)Entity.Contants.Types.OrderPriceType.OPTLimited)
                    {
                        limit_SingleRequestQuantity = singleRequestQuantity;
                    }
                    else if (val == (int)Entity.Contants.Types.OrderPriceType.OPTMarketPrice)
                    {
                        market_SingleRequestQuantity = singleRequestQuantity;
                    }
                }
            }

            //进行最大委托量校验
            switch (request.OrderWay)
            {
            case Entity.Contants.Types.OrderPriceType.OPTLimited:
                if (limit_SingleRequestQuantity == null)
                {
                    return(false);
                }
                if (!limit_SingleRequestQuantity.MaxConsignQuanturm.HasValue)
                {
                    return(false);
                }
                var maxLimitAmount = limit_SingleRequestQuantity.MaxConsignQuanturm.Value * scale2;
                if (orderAmount > maxLimitAmount)
                {
                    return(false);
                }

                break;

            case Entity.Contants.Types.OrderPriceType.OPTMarketPrice:
                if (market_SingleRequestQuantity == null)
                {
                    return(false);
                }
                if (!market_SingleRequestQuantity.MaxConsignQuanturm.HasValue)
                {
                    return(false);
                }
                var maxMarketAmount = market_SingleRequestQuantity.MaxConsignQuanturm.Value * scale2;
                if (orderAmount > maxMarketAmount)
                {
                    return(false);
                }
                break;
            }

            strMessage = "";
            return(true);
        }
 /// <summary>
 /// 检测:手续费<=可用资金
 /// </summary>
 /// <param name="request"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static bool CheckTradeMoney(MercantileFuturesOrderRequest request, ref string errMsg)
 {
     errMsg = "";
     return(false);
 }
        /// <summary>
        /// 获取商品期货交易费用内部方法
        /// </summary>
        /// <param name="request">期货委托</param>
        /// <param name="cost">费用数据实体</param>
        /// <returns>商品期货交易费用结果</returns>
        private static QHCostResult InternalComputeSPQHCost(MercantileFuturesOrderRequest request, QH_FutureCosts cost)
        {
            QHCostResult result = new QHCostResult();

            //result.Code = result.Code;
            result.Code = request.Code;
            decimal orderPrice = (decimal)request.OrderPrice;
            //期货合约乘数300
            decimal scale = MCService.GetTradeUnitScale(request.Code, request.OrderUnitType);
            //以计价单位计算的委托量
            var orderAmount = (decimal)request.OrderAmount * scale;

            //成交额
            var dealAmount = orderPrice * orderAmount;

            decimal cosing = 0;

            //按类型计算比例
            switch ((Types.FutrueCostType)Enum.Parse(typeof(Types.FutrueCostType), cost.CostType.ToString()))
            {
            case Types.FutrueCostType.TradeUnitCharge:
                //与量有关的都是撮合单位,所以这里不用再把委托量*转换比例
                //为了不改上面的代码这里直接再把原来转了的值再除
                orderAmount = (decimal)orderAmount / scale;
                cosing      = orderAmount * cost.TurnoverRateOfServiceCharge;
                break;

            case Types.FutrueCostType.TurnoverRateOfSerCha:
                //比例
                decimal cosingScale = cost.TurnoverRateOfServiceCharge / 100;
                cosing = dealAmount * cosingScale;
                break;
            }
            cosing = Utils.Round(cosing);

            #region old code
            //decimal tradeVal = 0;
            ////成交单位比率
            //if (cost.TradeUnitCharge.HasValue)
            //{
            //    decimal trade = cost.TradeUnitCharge.Value / 100;
            //    tradeVal = orderAmount * trade;
            //    tradeVal = Utils.Round(tradeVal);
            //}

            //decimal turnVal = 0;
            ////成交金额比率
            //if (cost.TurnoverRateOfServiceCharge.HasValue)
            //{
            //    decimal turn = cost.TurnoverRateOfServiceCharge.Value / 100;
            //    turnVal = turn * dealAmount;
            //    turnVal = Utils.Round(turnVal);
            //}
            //result.Cosing = tradeVal + turnVal;
            #endregion

            result.Cosing = cosing;

            string format = "商品期货费用计算[代码={0},价格={1},数量={2},单位={3},方向={4},合约乘数={5},商品期货交易费用类型={6},费用比率={7}]";
            string desc   = string.Format(format, request.Code, request.OrderPrice, request.OrderAmount,
                                          request.OrderUnitType, request.BuySell, scale
                                          , cost.CostType + "--" + (cost.CostType == (int)Types.FutrueCostType.TradeUnitCharge ? "按成交量" : "按成交额")
                                          , cost.TurnoverRateOfServiceCharge);
            LogHelper.WriteDebug(desc + result);

            return(result);
        }
 /// <summary>
 /// 检测合约是否存在
 /// </summary>
 /// <param name="request"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static bool CheckContractExist(MercantileFuturesOrderRequest request, ref string errMsg)
 {
     errMsg = "";
     return(false);
 }