示例#1
0
        /// <summary>
        /// 商品期货行情转换成自定义行情实体
        /// </summary>
        /// <param name="hqData">自定义实体</param>
        /// <returns></returns>
        public MarketDataLevel MerFutDataConvertMarketDataLevel(MerFutData hqData)
        {
            MarketDataLevel level = new MarketDataLevel();

            level.Code = hqData.CodeKey;
            level.Name = hqData.StrName;

            #region 买价
            level.BuyFirstPrice  = (decimal)hqData.Buyprice1;
            level.BuySecondPrice = (decimal)hqData.Buyprice2;
            level.BuyThirdPrice  = (decimal)hqData.Buyprice3;
            level.BuyFourthPrice = (decimal)hqData.Buyprice4;
            level.BuyFivePrice   = (decimal)hqData.Buyprice5;
            #endregion

            #region 买量
            level.BuyFirstVolume  = (decimal)hqData.Buyvol1;
            level.BuySecondVolume = (decimal)hqData.Buyvol2;
            level.BuyThirdVolume  = (decimal)hqData.Buyvol3;
            level.BuyFourthVolume = (decimal)hqData.Buyvol4;
            level.BuyFiveVolume   = (decimal)hqData.Buyvol5;
            #endregion

            #region 卖价
            level.SellFirstPrice  = (decimal)hqData.Sellprice1;
            level.SellSecondPrice = (decimal)hqData.Sellprice2;
            level.SellThirdPrice  = (decimal)hqData.Sellprice3;
            level.SellFourthPrice = (decimal)hqData.Sellprice4;
            level.SellFivePrice   = (decimal)hqData.Sellprice5;
            #endregion

            #region 卖量
            level.SellFirstVolume  = (decimal)hqData.Sellvol1;
            level.SellSecondVolume = (decimal)hqData.Sellvol2;
            level.SellThirdVolume  = (decimal)hqData.Sellvol3;
            level.SellFourthVolume = (decimal)hqData.Sellvol4;
            level.SellFiveVolume   = (decimal)hqData.Sellvol5;
            #endregion

            level.LastPrice         = decimal.Parse(hqData.Lasttrade.ToString());
            level.LastVolume        = decimal.Parse(hqData.PTrans.ToString());
            level.LowerPrice        = decimal.Parse(hqData.LowerLimit.ToString());
            level.UpPrice           = decimal.Parse(hqData.UpperLimit.ToString());
            level.YesterPrice       = decimal.Parse(hqData.PreClosePrice.ToString());
            level.MarketRefreshTime = DateTime.Parse(hqData.Time);
            return(level);
        }
示例#2
0
        /// <summary>
        /// 处理交割月合约保证金
        /// </summary>
        /// <param name="code">合约代码</param>
        /// <param name="compareDate">要比较的日期</param>
        /// <param name="breedClassID">合约代码所属品种类型</param>
        /// <returns>保证金比例</returns>
        private static decimal ProcessDeliveryMonth(string code, DateTime compareDate, int breedClassID)
        {
            string errCode = "GT-8482";
            string errMsg  = "无法根据期货商品代码获取其对应的保证金比例。";


            IList <QH_CFBailScaleValue> values = GetBailScaleValues(code, breedClassID);

            if (values == null)
            {
                throw new VTException(errCode, errMsg);
            }



            //如果是过期合约不用获取行情的持仓量,这是为了盘前检查,因为交割月的比例计算没有用到行情持仓量
            //持仓量----这里为了不用修改后面的代码设置如果合约是过期时直接给予市场持仓量为最大值,这是为了盘前检查时要计算一些强制平仓过期合约而设置
            //因为过期后的合约直接取交割月的其中一个比例,而这里设置这个持仓量是为了不知道此代码所设置的保证金比例计算方式是以天计算还是双边、单边计算
            decimal openInterest = int.MaxValue;

            if (!FutureService.CheckQHContractIsExpired(code))
            {
                IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
                //FutData futData = service.GetFutData(code);
                MerFutData merFutData = service.GetMercantileFutData(code);
                if (merFutData == null)
                {
                    errMsg = "处理交割月合约保证金时无法获取行情。";
                    throw new VTException(errCode, errMsg);
                }
                //持仓量
                openInterest = (decimal)merFutData.OpenInterest;
            }


            Types.QHCFPositionMonthType monthType   = Types.QHCFPositionMonthType.OnDelivery;
            IList <QH_CFBailScaleValue> scaleValues = FindScaleValuesByMonthType(values, monthType);

            if (scaleValues.Count != 0)
            {
                return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
            }

            return(-1);
        }
示例#3
0
        /// <summary>
        /// Desc: 根据商品期货合约代码获取当前代码行情
        /// Create by: 董鹏
        /// Create Date: 2010-01-25
        /// </summary>
        /// <param name="contractCode">合约代码</param>
        /// <returns></returns>
        public static MerFutData GetRealTimeCommditiesDataByContractCode(string contractCode)
        {
            //撮合中心代码不能为空
            if (string.IsNullOrEmpty(contractCode))
            {
                return(null);
            }
            IRealtimeMarketService realTimeService = GetRealtimeMark();

            //撮合中心实体不能为空
            if (realTimeService == null)
            {
                return(null);
            }
            MerFutData vtFutData = realTimeService.GetMercantileFutData(contractCode);

            return(vtFutData);
        }
        /// <summary>
        /// 处理交割月合约持仓限制
        /// </summary>
        /// <param name="code">合约代码</param>
        /// <param name="positionValueType">持仓限制类型</param>
        /// <returns>持仓限制</returns>
        private static PositionLimitValueInfo ProcessDeliveryMonth(string code, out Types.QHPositionValueType positionValueType)
        {
            string errCode = "GT-8492";
            string errMsg  = "无法根据商品期货商品代码获取其对应的持仓限制。";


            //根据合约代码获取其持仓限制列表
            IList <QH_PositionLimitValue> values = GetPositionLimitValues(code);

            if (values == null)
            {
                throw new VTException(errCode, errMsg);
            }

            #region 获取行情持仓量
            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            //FutData futData = service.GetFutData(code);
            MerFutData merFutData = service.GetMercantileFutData(code);
            if (merFutData == null)
            {
                errMsg = "处理交割月合约保证金时无法获取行情-持仓限制。";
                throw new VTException(errCode, errMsg);
            }

            //持仓量
            decimal openInterest = (decimal)merFutData.OpenInterest;
            LogHelper.WriteDebug("交割月份的合约当前获取到" + code + "行情持仓量:" + openInterest);
            #endregion

            #region 过滤所属持仓限制类型记录
            Types.QHCFPositionMonthType   monthType   = Types.QHCFPositionMonthType.OnDelivery;
            IList <QH_PositionLimitValue> limitValues = FindLimitValuesByMonthType(values, monthType);
            #endregion

            positionValueType = Types.QHPositionValueType.Scales;
            if (limitValues.Count != 0)
            {
                return(GetLimitByBailType(limitValues, openInterest, out positionValueType));
            }

            throw new VTException(errCode, errMsg);
            // return -1;
        }
示例#5
0
        /// <summary>
        /// Title:根据代码和代码所属类型获取最后成交价(最新成交价)
        /// Create by:李健华
        /// Create Date:2009-11-08
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public MarketDataLevel GetLastPriceByCode(string code, int breedClassType, out string errMsg)
        {
            MarketDataLevel result = null;

            errMsg = "";
            try
            {
                switch ((Types.BreedClassTypeEnum)breedClassType)
                {
                case Types.BreedClassTypeEnum.Stock:
                    HqExData data = GetRealMarketService().GetStockHqData(code);
                    if (data == null || data.HqData == null)
                    {
                        errMsg = "GT-0023:无法获取当前现货代码相关行情";
                        return(result);
                    }
                    // HqExData exData = data;
                    //float lastPrice = exData.HqData.Lasttrade;
                    //result = (decimal)lastPrice;
                    result = HqExDataConvertMarketDataLevel(data);
                    break;

                case Types.BreedClassTypeEnum.CommodityFuture:
                    //add by 董鹏 2010-01-26
                    MerFutData cfdata = GetRealMarketService().GetMercantileFutData(code);
                    if (cfdata == null)
                    {
                        errMsg = "GT-0023:无法获取当前商品期货代码相关行情";
                        return(result);
                    }
                    //MerFutData cforgData = cfdata;
                    //double cflastPrice = cforgData.Lasttrade;
                    //result = (decimal)cflastPrice;
                    result = MerFutDataConvertMarketDataLevel(cfdata);
                    break;

                case Types.BreedClassTypeEnum.StockIndexFuture:
                    FutData qhdata = GetRealMarketService().GetFutData(code);
                    if (qhdata == null)
                    {
                        errMsg = "GT-0023:无法获取当前股指期货代码相关行情";
                        return(result);
                    }
                    //FutData orgData = qhdata;
                    //double qhlastPrice = orgData.Lasttrade;
                    //result = (decimal)qhlastPrice;
                    result = FutDataDataConvertMarketDataLevel(qhdata);
                    break;

                case Types.BreedClassTypeEnum.HKStock:
                    HKStock hkdata = GetRealMarketService().GetHKStockData(code);
                    if (hkdata == null)
                    {
                        errMsg = "GT-0023:无法获取当前港股代码相关行情";
                        return(result);
                    }
                    //double hkLastPrice = hkdata.Lasttrade;
                    //result = (decimal)hkLastPrice;
                    result = HKStockDataConvertMarketDataLevel(hkdata);
                    break;

                default:
                    errMsg = "GT-0023:无此代码所属类型的行情";
                    break;
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                LogHelper.WriteError("GT-0023:根据代码和代码所属类型获取最后成交价(最新成交价)异常", ex);
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// 处理费交割月份的合约
        /// </summary>
        /// <param name="code">合约代码</param>
        /// <param name="year">合约年</param>
        /// <param name="month">合约月</param>
        /// <param name="compareDate">要比较的日期</param>
        /// <param name="breedClassID">合约代码所属品种类型</param>
        /// <returns>保证金比例</returns>
        private static decimal ProcessNonDeliveryMonth(string code, int year, int month, DateTime compareDate, int breedClassID)
        {
            string errCode = "GT-8482";
            string errMsg  = "无法根据期货商品代码获取其对应的保证金比例。";


            IList <QH_CFBailScaleValue> values = GetBailScaleValues(code, breedClassID);

            if (values == null || values.Count <= 0)
            {
                throw new VTException(errCode, errMsg);
            }

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            //FutData futData = service.GetFutData(code);
            MerFutData merFutData = service.GetMercantileFutData(code);

            if (merFutData == null)
            {
                errMsg = "处理交割月合约保证金时无法获取行情。";
                throw new VTException(errCode, errMsg);
            }

            //持仓量
            decimal openInterest = (decimal)merFutData.OpenInterest;

            //判断当前月份是那种交割月份类型
            Types.QHCFPositionMonthType monthType = FutureService.CheckMonthType(year, month, compareDate);

            IList <QH_CFBailScaleValue> scaleValues;

            #region  前三个月交割月份
            //如果是前三
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoThreeMonth)
            {
                scaleValues = FindScaleValuesByMonthType(values, monthType);

                //是前三
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }

                //否则就是一般月份
                scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }
            }
            #endregion

            #region 前二
            //如果是前二
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoTwoMonth)
            {
                scaleValues = FindScaleValuesByMonthType(values, monthType);

                //是前二
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }

                //否则就是一般月份
                scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }
            }
            #endregion

            #region 前一

            //如果是前一
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoMonth)
            {
                scaleValues = FindScaleValuesByMonthType(values, monthType);

                //是前一
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }

                //否则就是一般月份
                scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }
            }
            #endregion

            #region 一般月份
            //如果是一般月份
            if (monthType == Types.QHCFPositionMonthType.GeneralMonth)
            {
                scaleValues = FindScaleValuesByMonthType(values, monthType);

                //是一般月份
                if (scaleValues.Count > 0)
                {
                    return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID));
                }
            }
            #endregion

            #region 最低保证金
            QH_SIFBail sifBail = MCService.FuturesTradeRules.GetSIFBailByBreedClassID(breedClassID);
            if (sifBail == null)
            {
                LogHelper.WriteError("Debug_Test_Bail_ProcessNonDeliveryMonth_01:无法获取最低交易保证金比例", new Exception(""));
                return(-1);
            }
            else
            {
                LogHelper.WriteDebug("Debug_Test_Bail_ProcessNonDeliveryMonth_02:无对应的保证金比例区间范围值获取最低交易保证金比例" + sifBail.BailScale);

                return(sifBail.BailScale);
            }
            #endregion

            //return -1;
        }
        /// <summary>
        /// 处理非交割月份的合约
        /// </summary>
        /// <param name="code">合约代码</param>
        /// <param name="year">合约年</param>
        /// <param name="month">合约月</param>
        /// <param name="positionValueType">持仓限制类型</param>
        /// <returns>保证金比例</returns>
        private static PositionLimitValueInfo ProcessNonDeliveryMonth(string code, int year, int month, out Types.QHPositionValueType positionValueType)
        {
            string errCode = "GT-8492";
            string errMsg  = "无法根据期货商品代码获取其对应的持仓限制。";


            IList <QH_PositionLimitValue> values = GetPositionLimitValues(code);

            if (values == null)
            {
                throw new VTException(errCode, errMsg);
            }

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            //FutData futData = service.GetFutData(code);
            MerFutData merFutData = service.GetMercantileFutData(code);

            if (merFutData == null)
            {
                errMsg = "处理交割月合约保证金时无法获取行情-持仓限制。";
                throw new VTException(errCode, errMsg);
            }

            //持仓量
            decimal openInterest = (decimal)merFutData.OpenInterest;

            LogHelper.WriteDebug("非交割月份的合约当前获取到" + code + "行情持仓量:" + openInterest);

            //判断当前月份是那种交割月份类型
            Types.QHCFPositionMonthType monthType = FutureService.CheckMonthType(year, month, DateTime.Now);

            IList <QH_PositionLimitValue> limitValues;

            positionValueType = Types.QHPositionValueType.Scales;

            #region 交割月份前三个月
            //如果是前三
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoThreeMonth)
            {
                limitValues = FindLimitValuesByMonthType(values, monthType);

                //是前三
                if (limitValues.Count > 0)
                {
                    return(GetLimitByBailType(limitValues, openInterest, out positionValueType));
                }
                errMsg = "代码" + code + " 无法获取交割前三个月的对应的持仓限制列表参数正在以一般月份查询。";
                LogHelper.WriteDebug(errCode + errMsg);

                //否则就是一般月份
                limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (limitValues.Count > 0)
                {
                    PositionLimitValueInfo generOnThree = GetLimitByBailType(limitValues, openInterest, out positionValueType);
                    if (generOnThree.PositionValue == -1)
                    {
                        generOnThree.IsNoComputer = true;
                    }
                    return(generOnThree);
                }
                errMsg = "代码" + code + " 无法获取交割月份前三个月的一般月份的对应的持仓限制列表参数。";
                LogHelper.WriteDebug(errCode + errMsg);
            }
            #endregion

            #region 交割月份前二个月
            //如果是前二
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoTwoMonth)
            {
                limitValues = FindLimitValuesByMonthType(values, monthType);

                //是前二
                if (limitValues.Count > 0)
                {
                    return(GetLimitByBailType(limitValues, openInterest, out positionValueType));
                }
                errMsg = "代码" + code + " 无法获取交割前两个月的对应的持仓限制列表参数。";
                LogHelper.WriteDebug(errCode + errMsg);
                //否则就是一般月份
                limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (limitValues.Count > 0)
                {
                    PositionLimitValueInfo generOnDeliAgo = GetLimitByBailType(limitValues, openInterest, out positionValueType);
                    if (generOnDeliAgo.PositionValue == -1)
                    {
                        generOnDeliAgo.IsNoComputer = true;
                    }
                    return(generOnDeliAgo);
                }
                errMsg = "代码" + code + " 无法获取交割月份前两个月的一般月份的对应的持仓限制列表参数。";
                LogHelper.WriteDebug(errCode + errMsg);
            }
            #endregion

            #region 交割月份前一个月
            //如果是前一
            if (monthType == Types.QHCFPositionMonthType.OnDeliAgoMonth)
            {
                limitValues = FindLimitValuesByMonthType(values, monthType);

                //是前一
                if (limitValues.Count > 0)
                {
                    return(GetLimitByBailType(limitValues, openInterest, out positionValueType));
                }
                errMsg = "代码" + code + " 无法获取交割前一个月的对应的持仓限制列表参数正在以一般月份查询。";
                LogHelper.WriteDebug(errCode + errMsg);



                //否则就是一般月份
                limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth);
                if (limitValues.Count > 0)
                {
                    PositionLimitValueInfo generOnDeli = GetLimitByBailType(limitValues, openInterest, out positionValueType);
                    if (generOnDeli.PositionValue == -1)
                    {
                        generOnDeli.IsNoComputer = true;
                    }
                    return(generOnDeli);
                }
                errMsg = "代码" + code + " 无法获取交割月份前一个月的一般月份的对应的持仓限制列表参数。";
                LogHelper.WriteDebug(errCode + errMsg);
            }
            #endregion

            #region 交割月份一般月份
            //如果是一般月份
            if (monthType == Types.QHCFPositionMonthType.GeneralMonth)
            {
                limitValues = FindLimitValuesByMonthType(values, monthType);

                //是一般月份
                if (limitValues.Count > 0)
                {
                    PositionLimitValueInfo gener = GetLimitByBailType(limitValues, openInterest, out positionValueType);
                    if (gener.PositionValue == -1)
                    {
                        gener.IsNoComputer = true;
                    }
                    return(gener);
                }
                errMsg = "代码" + code + " 无法获取一般月份的对应的持仓限制列表参数。";
                LogHelper.WriteDebug(errCode + errMsg);
            }
            #endregion

            PositionLimitValueInfo info = new PositionLimitValueInfo();
            info.PositionValue    = -1;
            info.IsMinMultiple    = false;
            info.MinMultipleValue = 0;
            //return -1;
            return(info);
        }