Esempio n. 1
0
        private IList <data.PriceInfo> GetStockPriceFromServer(string code, string targetUrl)
        {
            IList <data.PriceInfo> stockList = new List <data.PriceInfo>();
            string content = this.getRequestContent(new Uri(targetUrl));

            if (content.Contains("<html>") || content.Contains("404 Not Found"))
            {
                return(new List <data.PriceInfo>());
            }


            Regex reg    = new Regex("\"[^\"]+\"");
            var   matchs = reg.Matches(content);

            foreach (Match match in matchs)
            {
                string[] vs        = match.Value.Trim('\"').Split(new string[] { "\\n\\\n" }, StringSplitOptions.RemoveEmptyEntries);
                decimal  yestclose = 0;
                foreach (string v in vs)
                {
                    string[] sps = v.Trim('\"').Split(' ');

                    string date = string.Empty;

                    if (sps[0].StartsWith("8") || sps[0].StartsWith("9"))
                    {
                        date = "19" + sps[0];
                    }
                    else
                    {
                        date = "20" + sps[0];
                    }

                    DateTime datetime = new DateTime(int.Parse(date.Substring(0, 4)), int.Parse(date.Substring(4, 2)), int.Parse(date.Substring(6)));

                    data.PriceInfo sp = new data.PriceInfo();
                    sp.code   = code;
                    sp.date   = datetime;
                    sp.open   = decimal.Parse(sps[1]);
                    sp.price  = decimal.Parse(sps[2]);//
                    sp.high   = decimal.Parse(sps[3]);
                    sp.low    = decimal.Parse(sps[4]);
                    sp.volume = decimal.Parse(sps[5]);
                    stockList.Add(sp);
                }
            }
            return(stockList);
        }
Esempio n. 2
0
        private IList <data.PriceInfo> GetPriceList(string code)
        {
            IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>();

            DateTime today     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            decimal  yestclose = GetYestclose(code, today);

            //获取基期的值
            int     i         = -1;
            bool    isOk      = false;
            decimal baseValue = 0;

            while (!isOk)
            {
                var priceList = stockService.GetStockPriceByDate(code, data.TechCycle.day, DateTime.Now.AddDays(i--));
                if (priceList == null || priceList.Count == 0)
                {
                    continue;
                }
                decimal total = 0, baseIndex = 100;
                foreach (var priceInfo in priceList)
                {
                    total += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                }
                baseValue = (total * 100) / yestclose;
                isOk      = true;
            }

            //index = (total / baseValue) * 100;


            var     priceList0 = stockService.GetStockPriceByDate(code, data.TechCycle.day, today);
            decimal vol = 0, turnover = 0;
            decimal total1 = 0;

            foreach (var priceInfo in priceList0)
            {
                total1   += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                vol      += priceInfo.volume ?? 1;
                turnover += priceInfo.turnover ?? 1;
            }

            decimal index = (total1 / baseValue) * 100;

            var percent = (index - yestclose) * 100 / yestclose;
            var info    = new data.PriceInfo
            {
                code      = code,
                date      = today,
                price     = Math.Round(index, 2),
                high      = 0,
                low       = 0,
                yestclose = yestclose,
                volume    = vol,
                turnover  = turnover,
                percent   = percent,
                open      = Math.Round(index, 2),
            };

            priceInfoList.Add(info);
            this.Log().Info(string.Format("行业:{0},值:{1}", code, info.price));
            return(priceInfoList);
        }
Esempio n. 3
0
        /// <summary>
        /// 计算某行业,每周期的指数值
        /// </summary>
        /// <param name="categoryCode"></param>
        /// <param name="cycle"></param>
        private void InitCategoryIndexByCycle(string categoryCode, data.TechCycle cycle)
        {
            //获取某只股票的所有价格列表

            var     stocks    = stockService.GetPriceInfo("0600000", cycle);
            decimal yestclose = 0;
            decimal baseIndex = 100;
            decimal baseValue = 0;

            //计算每个周期的指数值
            for (int i = 0; i < stocks.Count; i++)
            {
                var stock     = stocks[i];
                var priceList = stockService.GetStockPriceByDate(categoryCode, cycle, stock.date);
                if (priceList == null || priceList.Count == 0)
                {
                    continue;
                }
                decimal total = 0, vol = 0, turnover = 0, index = 0;
                foreach (var priceInfo in priceList)
                {
                    total    += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                if (baseValue == 0)
                {
                    baseValue = total;
                    index     = 100;
                }
                else
                {
                    index = (total / baseValue) * 100;
                }

                var info = new data.PriceInfo
                {
                    code      = categoryCode,
                    date      = stock.date,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover,
                    open      = Math.Round(index, 2),
                };

                yestclose = index;

                try
                {
                    //cateService.AddPriceInfo(categoryCode, info, cycle);
                    if (cycle == TechCycle.day)
                    {
                        cateService.AddPriceByDay <data_category_day_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.week)
                    {
                        cateService.AddPriceByWeek <data_category_week_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.month)
                    {
                        cateService.AddPriceByMonth <data_category_month_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }

                    this.Log().Info(string.Format("行业指数:周期:{0},日期:{1},类别:{2},数值:{3}", cycle, info.date, categoryCode, info.price));
                }
                catch (Exception ex)
                {
                    //(new System.Collections.Generic.Mscorlib_CollectionDebugView<System.Data.Entity.Validation.DbEntityValidationResult>(((System.Data.Entity.Validation.DbEntityValidationException)(ex)).EntityValidationErrors as System.Collections.Generic.List<System.Data.Entity.Validation.DbEntityValidationResult>)).Items[0].ValidationErrors


                    this.Log().Error(ex.Message);
                }
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>();

            this.Log().Info("计算开始");
            //获取行业列表
            IList <data.stockcategory> list;

            if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1")
            {
                list = cateService.GetCategoryList("tencent");
            }
            else
            {
                string[] cates = this.CategoryCode.Split(',');
                list = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList();
            }


            //遍历列表,获取行业下的股票,计算指数,更新指数

            IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>();

            foreach (var item in list)
            {
                //IList<data.stock> stocks = stockService.GetStockByCategory(item.code);
                DateTime today     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                decimal  yestclose = GetYestclose(item.code, today);

                //获取基期的值
                int     i         = -1;
                bool    isOk      = false;
                decimal baseValue = 0;
                while (!isOk)
                {
                    var priceList = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, DateTime.Now.AddDays(i--));
                    if (priceList == null || priceList.Count == 0)
                    {
                        continue;
                    }
                    decimal total = 0, baseIndex = 100;
                    foreach (var priceInfo in priceList)
                    {
                        total += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    }
                    baseValue = (total * 100) / yestclose;
                    isOk      = true;
                }

                //index = (total / baseValue) * 100;


                var     priceList0 = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, today);
                decimal vol = 0, turnover = 0;
                decimal total1 = 0;
                foreach (var priceInfo in priceList0)
                {
                    total1   += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                decimal index = (total1 / baseValue) * 100;

                var percent = (index - yestclose) * 100 / yestclose;
                var info    = new data.PriceInfo
                {
                    code      = item.code,
                    date      = today,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover,
                    percent   = percent,
                    open      = Math.Round(index, 2),
                };

                priceInfoList.Add(info);
                this.Log().Info(string.Format("行业:{0},值:{1}", item.code, info.price));
            }
            cateService.UpdateCategoryPrice(priceInfoList);
            cateService.AddPriceByDay <data.data_category_day_latest>(priceInfoList);
            cateService.AddPriceByWeek <data.data_category_week_latest>(priceInfoList);
            cateService.AddPriceByMonth <data.data_category_month_latest>(priceInfoList);
            this.Log().Info("计算结束");
        }
Esempio n. 5
0
        private void UpdateCategory()
        {
            IList <data.stockcategory> list = cateService.GetCategoryList("tencent");

            //遍历列表,获取行业下的股票,计算指数,更新指数

            IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>();

            foreach (var item in list)
            {
                //IList<data.stock> stocks = stockService.GetStockByCategory(item.code);
                DateTime today     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                decimal  yestclose = GetYestclose(item.code, today);

                //获取基期的值
                int     i         = -1;
                bool    isOk      = false;
                decimal baseValue = 0;
                while (!isOk)
                {
                    var priceList = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, DateTime.Now.AddDays(i--));
                    if (priceList == null || priceList.Count == 0)
                    {
                        continue;
                    }
                    decimal total = 0, baseIndex = 100;
                    foreach (var priceInfo in priceList)
                    {
                        total += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    }
                    baseValue = (total * 100) / yestclose;
                    isOk      = true;
                }

                //index = (total / baseValue) * 100;


                var     priceList0 = GetCurrentCategoryPrice(item.code);
                decimal vol = 0, turnover = 0;
                decimal total1 = 0;
                foreach (var priceInfo in priceList0)
                {
                    total1   += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                decimal index = (total1 / baseValue) * 100;

                var info = new data.PriceInfo
                {
                    code      = item.code,
                    date      = today,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover
                };

                priceInfoList.Add(info);
                this.Log().Info(string.Format("行业:{0},值:{1}", item.code, info.price));
            }

            foreach (var info in priceInfoList)
            {
                this.Log().Info("更新行业:" + string.Format("{0}_{1}", (int)ObjectType.Category, info.code) + ":" + info.code);

                UpdateRealTimePrice(ObjectType.Category, info);

                UpdateDayPrice(ObjectType.Category, info);

                //UpdatePrice(ObjectType.Category, TechCycle.Week, info);

                //UpdatePrice(ObjectType.Category, TechCycle.Month, info);
            }
            //cateService.UpdateCategoryPrice(priceInfoList);
            //cateService.AddPriceByDay<data.data_category_day_latest>(priceInfoList);
            //cateService.AddPriceByWeek<data.data_category_week_latest>(priceInfoList);
            //cateService.AddPriceByMonth<data.data_category_month_latest>(priceInfoList);
            this.Log().Info("计算结束");
        }