private bool ImportDay(data.stock stock)
        {
            try
            {
                IList <data.PriceInfo> spday = sync.GetPriceByDay(stock);

                var list = spday.OrderBy(p => p.date).ToList();

                for (int i = 1; i < list.Count(); i++)
                {
                    list[i].yestclose = list[i - 1].price;
                    list[i].updown    = list[i].price - list[i].yestclose;
                    list[i].percent   = list[i].updown / list[i].yestclose;
                }

                stockService.AddPriceByDay <data.data_stock_day_latest>(spday, false);
                this.Log().Info("日线:" + stock.code + stock.name);
                return(true);
            }
            catch (Exception ex)
            {
                stockService.AddPriceSyncLog(new data.pricesynclog
                {
                    batch       = this.batch.ToString(),
                    stock_code  = stock.code,
                    description = ex.GetBaseException().Message,
                    creatime    = DateTime.Now,
                    type        = "day"
                });
                return(false);
            }
        }
 private void clearTechData(data.stock stock)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         string sql = string.Format("delete from tech_context where object_code='{0}'", stock.code);
         entity.Database.ExecuteSqlCommand(sql);
     }
 }
Beispiel #3
0
        public IList <data.PriceInfo> GetPriceByMonth(data.stock stock)
        {
            //http://data.gtimg.cn/flashdata/hushen/monthly/sh600050.js
            string url  = "http://data.gtimg.cn/flashdata/hushen/monthly/{0}.js";
            string code = GetStockCode(stock);
            List <data.StockInfo> stockList = new List <data.StockInfo>();

            string target = string.Format(url, code);

            var tempList = GetStockPriceFromServer(stock.code, target);

            return(tempList);
        }
Beispiel #4
0
        public IList <data.stock> GetStocks(data.stockcategory category)
        {
            IList <string>          codes   = getStockCodeList(category);
            IList <IList <string> > codeStr = new List <IList <string> >();
            int num = 10;

            if (codes.Count > 10)
            {
                for (int i = 0; i < codes.Count; i = i + num)
                {
                    codeStr.Add(codes.Skip(i).Take(num).ToList());
                }
            }
            else
            {
                codeStr.Add(codes);
            }

            IList <data.stock> stockList = new List <data.stock>();

            foreach (IList <string> sub in codeStr)
            {
                string url2 = "http://push3.gtimg.cn/q={0}&m=push&r={1}";
                Uri    uri  = new Uri(string.Format(url2, string.Join(",", sub), new Random().ToString()));
                //pv_sz000718="51~苏宁环球~000718~4.65~4.63~4.65~181492~70761~110731~4.64~1372~4.63~3972~4.62~3000~4.61~5423~4.60~1117~4.65~3246~4.66~1875~4.67~2492~4.68~3955~4.69~2481~15:00:20/4.65/3400/S/1581372/21958|14:56:56/4.65/50/S/23250/21784|14:56:53/4.66/20/B/9320/21779|14:56:47/4.65/29/S/13509/21768|14:56:38/4.65/14/S/6510/21756|14:56:38/4.66/24/B/11184/21750~20140704150411~0.02~0.43~4.69~4.58~4.65/178092/82605364~181492~8419~1.23~103.55~~4.69~4.58~2.38~68.35~95.01~2.19~5.09~4.17~";

                string   content   = getRequestContent(uri);
                string[] stockStrs = content.Split('\n');

                foreach (string stockStr in stockStrs)
                {
                    Regex reg    = new Regex("\"[^\"]+\"");
                    var   matchs = reg.Matches(stockStr);

                    foreach (Match match in matchs)
                    {
                        string[]   vs    = match.Value.Trim('\"').Split('~');
                        data.stock stock = new data.stock();
                        stock.code = (vs[0] == "51" ? "1" : "0") + vs[2];
                        //stock.cate_code = category.code;
                        stock.name      = vs[1];
                        stock.price     = decimal.Parse(vs[3]);
                        stock.yestclose = decimal.Parse(vs[4]);
                        stock.symbol    = "";
                        stockList.Add(stock);
                        Console.WriteLine(stock.code + "-" + stock.name + "-" + stock.price);
                    }
                }
            }
            return(stockList);
        }
Beispiel #5
0
        /// <summary>
        /// 或者针对腾讯网站的编码
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        private string GetStockCode(data.stock stock)
        {
            string prifix = string.Empty;

            if (stock.code.Substring(0, 1) == "0")
            {
                prifix = "sh";
            }
            else if (stock.code.Substring(0, 1) == "1")
            {
                prifix = "sz";
            }
            return(prifix + stock.code.Substring(1));
        }
        private bool ImportMonth(data.stock stock, DateTime startDate)
        {
            IList <data.PriceInfo> spmonth = sync.GetPriceByMonth(stock);

            var list = spmonth.Where(p => p.date >= startDate.AddDays(-30)).OrderBy(p => p.date).ToList();

            for (int i = 1; i < list.Count(); i++)
            {
                list[i].yestclose = list[i - 1].price;
                list[i].updown    = list[i].price - list[i].yestclose;
                list[i].percent   = list[i].updown / list[i].yestclose;
            }
            if (list.Count > 0)
            {
                list.RemoveAt(0);
            }
            stockService.AddPriceByMonth <data.data_stock_month_latest>(list);
            this.Log().Info("月线:" + stock.code + stock.name);
            return(true);
        }
Beispiel #7
0
        public IList <data.PriceInfo> GetPriceByDay(data.stock stock)
        {
            //http://data.gtimg.cn/flashdata/hushen/daily/14/sh600050.js
            string url = "http://data.gtimg.cn/flashdata/hushen/daily/{0}/{1}.js";


            //daily_data_04="\n\
            //040102 3.93 4.12 4.17 3.91 1885527\n\
            //040105 4.13 4.53 4.53 4.13 3699816\n\
            //040106 4.59 4.88 4.98 4.56 4880455\n\
            //040107 4.88 4.78 4.97 4.73 3515511\n\
            //040108 4.75 4.94 5.05 4.72 2859660\n\
            //040109 4.92 4.87 5.11 4.84 2846707\n\
            //040112 4.89 5.02 5.04 4.78 2001276\n\
            //040113 5.04 4.89 5.08 4.82 1837009\n\
            //040114 4.88 4.74 4.90 4.72 1938512\n\
            //040115 4.74 4.74 4.82 4.72 1131030\n\
            //040116 4.76 4.74 4.79 4.61 1320374\n\
            //040129 4.78 4.86 4.95 4.78 1330404\n\
            //040130 4.89 4.87 5.03 4.84 1758014\n\
            //040202 5.36 5.17 5.36 5.03 4633113\n\
            //040203 5.18 5.15 5.19 5.07 1248059\n\

            string code = GetStockCode(stock);
            List <data.PriceInfo> stockList = new List <data.PriceInfo>();
            IList <string>        urls      = new List <string>();

            for (int i = 2010; i <= DateTime.Now.Year; i++)
            {
                string target = string.Format(url, (i.ToString()).Substring(2), code);

                var tempList = GetStockPriceFromServer(stock.code, target);
                if (tempList.Count <= 0)
                {
                    continue;
                }
                stockList.AddRange(tempList);
                Thread.Sleep(100);
            }
            return(stockList);
        }
        private bool ImportWeek(data.stock stock)
        {
            try
            {
                IList <data.PriceInfo> spweek = sync.GetPriceByWeek(stock);

                var list = spweek.OrderBy(p => p.date).ToList();

                for (int i = 1; i < list.Count(); i++)
                {
                    list[i].yestclose = list[i - 1].price;
                    list[i].updown    = list[i].price - list[i].yestclose;
                    list[i].percent   = list[i].updown / list[i].yestclose;
                }
                stockService.AddPriceByWeek <data.data_stock_week_latest>(spweek, false);
                this.Log().Info("周线:" + stock.code + stock.name);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }