/// <summary>
        /// 3.买一卖一百分比
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private bool CheckType3(StockOrderRequest request, HighLowRange highLowRange)
        {
            decimal highRange = highLowRange.HighRange;
            decimal lowRange  = highLowRange.LowRange;

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            HqExData data   = service.GetStockHqData(request.Code);
            HqExData exData = data;
            HqData   hqData = exData.HqData;

            float   b1   = hqData.Buyprice1;
            decimal buy1 = (decimal)b1;

            float   s1    = hqData.Sellprice1;
            decimal sell1 = (decimal)s1;

            decimal high = sell1 * highRange;
            decimal low  = buy1 * lowRange;


            decimal orderPrice = (decimal)request.OrderPrice;

            if (orderPrice >= low && orderPrice <= high)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// 1.昨日收盘价的上下百分比
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private bool CheckType1(StockOrderRequest request, HighLowRange highLowRange)
        {
            decimal highRange = highLowRange.HighRange;
            decimal lowRange  = highLowRange.LowRange;

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            HqExData data   = service.GetStockHqData(request.Code);
            HqExData exData = data;


            float   yClose    = exData.YClose;
            decimal yestPrice = (decimal)yClose;

            decimal high = yestPrice * (1 + highRange);
            decimal low  = yestPrice * (1 - lowRange);

            decimal orderPrice = (decimal)request.OrderPrice;

            if (orderPrice >= low && orderPrice <= high)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// 获取现货的最近成交价
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public decimal GetStockLastTrade(string code)
        {
            decimal result = -1;

            try
            {
                HqExData data = this.service.GetStockHqData(code);
                if (data == null)
                {
                    MessageBox.Show("GetStockHqData failure!");
                    return(result);
                }

                if (data != null)
                {
                    HqExData exData = data;

                    result = (decimal)exData.HqData.Lasttrade;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LogHelper.WriteError(ex.Message, ex);
            }

            return(result);
        }
        /// <summary>
        /// 5.港股买卖价位
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private bool CheckType5(StockOrderRequest request, HighLowRange highLowRange)
        {
            HKRange hkRange = highLowRange.HongKongRange;

            decimal buyHighRange  = hkRange.BuyHighRange;
            decimal buyLowRange   = hkRange.BuyLowRange;
            decimal sellHighRange = hkRange.SellHighRange;
            decimal sellLowRange  = hkRange.SellLowRange;

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            HqExData data   = service.GetStockHqData(request.Code);
            HqExData exData = data;
            HqData   hqData = exData.HqData;

            float   b1   = hqData.Buyprice1;
            decimal buy1 = (decimal)b1;

            float   s1    = hqData.Sellprice1;
            decimal sell1 = (decimal)s1;

            decimal buyH = sell1;
            decimal buyL = MCService.HLRangeProcessor.GetHKRangeValue(request.Code, (decimal)request.OrderPrice, buy1,
                                                                      -buyLowRange);

            decimal sellH = MCService.HLRangeProcessor.GetHKRangeValue(request.Code, (decimal)request.OrderPrice, sell1,
                                                                       sellHighRange);
            decimal sellL = buy1;

            decimal high = 0;
            decimal low  = 0;

            if (request.BuySell == Types.TransactionDirection.Buying)
            {
                low  = buyL;
                high = buyH;
            }
            else
            {
                low  = sellL;
                high = sellH;
            }

            decimal orderPrice = (decimal)request.OrderPrice;

            if (orderPrice >= low && orderPrice <= high)
            {
                return(true);
            }
            throw new NotImplementedException();
        }
Beispiel #5
0
        /// <summary>
        /// 现货行情转换成自定义行情实体
        /// </summary>
        /// <param name="data">自定义实体</param>
        /// <returns></returns>
        public MarketDataLevel HqExDataConvertMarketDataLevel(HqExData data)
        {
            MarketDataLevel level = new MarketDataLevel();

            level.Code = data.CodeKey;
            level.Name = data.Name;
            HqData hqData = data.HqData;

            #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(data.LastVolume.ToString());
            level.LowerPrice        = decimal.Parse(data.LowB.ToString());
            level.UpPrice           = decimal.Parse(data.UpB.ToString());
            level.YesterPrice       = decimal.Parse(data.YClose.ToString());
            level.MarketRefreshTime = data.HqData.Time;
            return(level);
        }
Beispiel #6
0
        /// <summary>
        ///根据现货代码获取当前代码行情
        /// </summary>
        /// <param name="commdityCode">代码</param>
        /// <returns></returns>
        public static HqExData GetRealTimeStockDataByCommdityCode(string commdityCode)
        {
            //撮合中心代码不能为空
            if (string.IsNullOrEmpty(commdityCode))
            {
                return(null);
            }
            IRealtimeMarketService realTimeService = GetRealtimeMark();

            //撮合中心实体不能为空
            if (realTimeService == null)
            {
                return(null);
            }
            HqExData vtHqExData = realTimeService.GetStockHqData(commdityCode);

            return(vtHqExData);
        }
Beispiel #7
0
        /// <summary>
        /// 获取现货的昨日收盘价
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public decimal GetStockYClose(string code)
        {
            decimal result = -1;

            stockYCloseDicLock.EnterUpgradeableReadLock();
            try
            {
                if (!stockYCloseDic.TryGetValue(code, out result))
                {
                    stockYCloseDicLock.EnterWriteLock();
                    try
                    {
                        HqExData data   = this.service.GetStockHqData(code);
                        HqExData exData = data;

                        float yClose = exData.YClose;
                        result = (decimal)yClose;

                        stockYCloseDic[code] = result;
                    }
                    catch (Exception ex)
                    {
                        result = -1;
                        LogHelper.WriteError(ex.Message, ex);
                    }
                    finally
                    {
                        stockYCloseDicLock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                stockYCloseDicLock.ExitUpgradeableReadLock();
            }

            return(result);
        }
        /// <summary>
        /// 6.最近成交价上下各多少元
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private bool CheckType6(StockOrderRequest request, HighLowRange highLowRange)
        {
            decimal highRange = highLowRange.HighRange;
            decimal lowRange  = highLowRange.LowRange;

            IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService();
            HqExData data   = service.GetStockHqData(request.Code);
            HqExData exData = data;

            float   rPrice      = exData.LastVolume;
            decimal recentPrice = (decimal)rPrice;

            decimal high = recentPrice + highRange;
            decimal low  = recentPrice - lowRange;

            decimal orderPrice = (decimal)request.OrderPrice;

            if (orderPrice >= low && orderPrice <= high)
            {
                return(true);
            }

            return(false);
        }
Beispiel #9
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);
        }