Esempio n. 1
0
        /// <summary>
        /// 获取股票时实信息
        /// </summary>
        /// <param name="Codes">股票代码集用 ',' 分隔</param>
        /// <param name="IsSimple">是否简单模式</param>
        /// <returns></returns>
        public static List <StockModel> GetStockInfo(string Codes, bool IsSimple)
        {
            List <StockModel> dic = new List <StockModel>();

            if (IsSimple)
            {
                Codes = ToSimlpeCodes(Codes);
            }

            string RequestUrl = GetRequstUrl(Codes);
            var    jsons      = RequsetJson(RequestUrl);

            if (jsons == "")
            {
                return(null);
            }
            var Ary = jsons.Split(';');

            foreach (string json in Ary)
            {
                if (json == "" || json.Length <= 10)
                {
                    continue;
                }
                StockModel m = IsSimple? SimpleJsonToStockModel(json): JsonToStockModel(json);
                dic.Add(m);
            }
            return(dic);
        }
Esempio n. 2
0
        public void ModifyItem(StockModel m, int index)
        {
            if (m.DiffPrice > 0)
            {
                ltView.Items[index].ForeColor = Color.Red;
            }
            else
            {
                ltView.Items[index].ForeColor = Color.Green;
            }

            ltView.Items[index].SubItems[1].Text = m.Code;
            ltView.Items[index].SubItems[2].Text = m.NowPrice.ToString();
            ltView.Items[index].SubItems[3].Text = string.Format("{0:0.00%}", m.DiffPercent);
            ltView.Items[index].SubItems[4].Text = m.DiffPrice.ToString();
        }
Esempio n. 3
0
        /// <summary>
        ///获取实时记录信息
        /// </summary>
        /// <param name="Codes">代码集</param>
        /// <param name="IsSimple">是否简单模式</param>
        /// <returns></returns>
        public static List <StockModel> GetStockInfo(List <string> Codes, bool IsSimple = false)
        {
            List <StockModel> dic = new List <StockModel>();

            foreach (string c in Codes)
            {
                string RequestUrl = GetRequstUrl(c, IsSimple);
                var    json       = RequsetJson(RequestUrl);
                if (json == "")
                {
                    return(null);
                }
                StockModel m = IsSimple? SimpleJsonToStockModel(json): JsonToStockModel(json);
                dic.Add(m);
            }
            return(dic);
        }
Esempio n. 4
0
        public void DelItem(StockModel m)
        {
            ListViewItem item = new ListViewItem();

            if (m.DiffPrice > 0)
            {
                item.ForeColor = Color.Red;
            }
            else
            {
                item.ForeColor = Color.Green;
            }
            item.Text = m.StockName;
            item.SubItems.Add(m.Code);
            item.SubItems.Add(m.NowPrice.ToString());
            item.SubItems.Add(string.Format("{0:0.00%}", m.DiffPercent));
            item.SubItems.Add(m.DiffPrice.ToString());
            ltView.Items.Remove(item);
        }
Esempio n. 5
0
        /// <summary>
        /// 请求的简单模式JSON转成实体
        /// </summary>
        /// <param name="Json">简单模式JSON</param>
        /// <returns></returns>
        private static StockModel SimpleJsonToStockModel(string simlpeJson)
        {
            //varhq_str_s_sh000001="上证指数,3094.668,-128.073,-3.97,436653,5458126";
            // 数据含义分别为:指数名称,当前点数,当前价格,涨跌率,成交量(手),成交额(万元);
            string[]   objs  = simlpeJson.Split(',');
            StockModel model = new StockModel();

            {
                var name = objs[0];
                model.Code        = name.Substring(name.LastIndexOf('_') + 1, 8);
                model.StockName   = name.Substring(name.LastIndexOf('"') + 1);
                model.NowPrice    = double.Parse(objs[2]);
                model.DiffPercent = double.Parse(objs[3]);
                model.DiffPrice   = double.Parse(objs[1]);
                model.DealNum     = int.Parse(objs[4].ToString());
                model.DealMoney   = double.Parse(objs[5].ToString().Remove(objs[5].ToString().IndexOf('"')));
            }
            return(model);
        }
Esempio n. 6
0
        /// <summary>
        /// 请求的JSON转成实体
        /// </summary>
        /// <param name="Json">JSON</param>
        /// <returns></returns>
        private static StockModel JsonToStockModel(string Json)
        {
            #region
            //0:”大秦铁路”,股票名字;
            //1:”27.55″,今日开盘价;
            //2:”27.25″,昨日收盘价;
            //3:”26.91″,当前价格;
            //4:”27.55″,今日最高价;
            //5:”26.20″,今日最低价;
            //6:”26.91″,竞买价,即“买一”报价;
            //7:”26.92″,竞卖价,即“卖一”报价;
            //8:”22114263″,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百;
            //9:”589824680″,成交金额,单位为“元”,为了一目了然,通常以“万元”为成交金额的单位,所以通常把该值除以一万;
            //10:”4695″,“买一”申请4695股,即47手;
            //11:”26.91″,“买一”报价;
            //12:”57590″,“买二”
            //13:”26.90″,“买二”
            //14:”14700″,“买三”
            //15:”26.89″,“买三”
            //16:”14300″,“买四”
            //17:”26.88″,“买四”
            //18:”15100″,“买五”
            //19:”26.87″,“买五”
            //20:”3100″,“卖一”申报3100股,即31手;
            //21:”26.92″,“卖一”报价
            //(22, 23), (24, 25), (26, 27), (28, 29)分别为“卖二”至“卖四的情况”
            //30:”2008 - 01 - 11″,日期;
            //31:”15:05:32″,时间;
            //32 股票状态
            #endregion
            string[] objs = Json.Split(',');

            StockModel model = new StockModel();
            {
                var name = objs[0];
                model.Code      = name.Substring(name.LastIndexOf('_') + 1, 8);
                model.StockName = name.Substring(name.LastIndexOf('"') + 1);

                model.TodayFirstPrice = double.Parse(objs[1]);
                model.YesterdayPrice  = double.Parse(objs[2]);
                model.NowPrice        = double.Parse(objs[3]);
                model.MaxPrice        = double.Parse(objs[4]);
                model.MinPrice        = double.Parse(objs[5]);
                model.BuyPrice        = double.Parse(objs[6]);
                model.SalePrice       = double.Parse(objs[7]);
                model.DealNum         = long.Parse(objs[8]) / 10000;
                model.DealMoney       = double.Parse(objs[9]) / 10000;

                model.BuyNum1 = int.Parse(objs[10]);
                model.BuyNum2 = int.Parse(objs[12]);
                model.BuyNum3 = int.Parse(objs[14]);
                model.BuyNum4 = int.Parse(objs[16]);
                model.BuyNum5 = int.Parse(objs[18]);

                model.BuyPrice1 = double.Parse(objs[11]);
                model.BuyPrice2 = double.Parse(objs[13]);
                model.BuyPrice3 = double.Parse(objs[15]);
                model.BuyPrice4 = double.Parse(objs[17]);
                model.BuyPrice5 = double.Parse(objs[19]);


                model.SaleNum1 = int.Parse(objs[20]);
                model.SaleNum2 = int.Parse(objs[22]);
                model.SaleNum3 = int.Parse(objs[24]);
                model.SaleNum4 = int.Parse(objs[26]);
                model.SaleNum5 = int.Parse(objs[28]);

                model.SalePrice1 = double.Parse(objs[22]);
                model.SalePrice2 = double.Parse(objs[23]);
                model.SalePrice3 = double.Parse(objs[25]);
                model.SalePrice4 = double.Parse(objs[27]);
                model.SalePrice5 = double.Parse(objs[29]);

                model.ToDay       = DateTime.Parse(objs[30]);
                model.NowTime     = objs[31];
                model.StatusCode  = objs[32];
                model.DiffPrice   = Math.Round((model.NowPrice - model.YesterdayPrice), 2);
                model.DiffPercent = model.YesterdayPrice == 0?0:Math.Round(((model.NowPrice - model.YesterdayPrice) / model.YesterdayPrice), 4);
            }
            return(model);
        }