Example #1
0
 /**
  * 
  * 大盘瞬时涨跌幅
  * */
 public static double getRealDpZf(DaoPan dp)
 {
     if (GPTotalAPI.dpMap.ContainsKey(dp.code))
     {
         DaoPan old_dp = GPTotalAPI.dpMap[dp.code];
         if (old_dp.zs > 0)
         {
             return Math.Round(((dp.zs - old_dp.zs) / old_dp.zs) * 100, 2);
         }
     }
     return 0;
 }
Example #2
0
        /**
     * 获取个股数据
         * 1, s_sh000001,s_sz399001,s_sz399006
         * 2, s_sz399001
         * 3, s_sz399006
     * */
        public static List<DaoPan> getDPList( string type
        )
        {
            string code = "s_sh000001";
            if ("0".Equals(type))
            {
                code = "s_sh000001";
            }
            else if ("1".Equals(type))
            {
                code = "s_sz399001";
            }
            else if ("2".Equals(type))
            {
                code = "s_sz399006";
            }
            else if ("nsdk".Equals(type))
            {
                code = "int_nasdaq";
            }
            else if ("dqs".Equals(type))
            {
                code = "int_dji";
            }
            else if ("hs".Equals(type))
            {
                code = "int_hangseng";
            }
            else
            {
                code = "s_sh000001,s_sz399001,s_sz399006,int_dji,int_nasdaq,int_hangseng";
            }
            //HttpClient client = new HttpClient("http://hq.sinajs.cn/list=" + code);
            //string data = client.GetString();
            string data = RealDataApi.getRequest("http://hq.sinajs.cn/list=" + code);
            if (String.IsNullOrEmpty(data))
            {
                return null;
            }
            else
            {
                data = data.Replace("\r\n", "").Replace("\"","");
            }

            List<DaoPan> dpList = new List<DaoPan>();
            string[] fieldList = data.Split(";".ToCharArray());
            string[] fields = null;
            string[] dpCodes = code.Split(",".ToCharArray());
            DaoPan dp = null;
            for (int i = 0; i < fieldList.Length; i++)
            {
                fields = fieldList[i].Split(",".ToCharArray());

                if (fields.Length <= 1)
                {
                    continue;
                }
                dp = new DaoPan();
                dp.code = dpCodes[i];
                dp.name = fields[0]; //指数名称
                dp.zs = Convert.ToDouble(fields[1]); //当前点数
                dp.zds = Convert.ToDouble(fields[2]); //当前价格
                dp.zdl = Convert.ToDouble(fields[3]); //涨跌率

                if (fields.Length > 4)
                {
                    dp.cjl = Convert.ToInt32(fields[4]);//成交量(手)
                    dp.cje = Convert.ToDouble(fields[5].Replace("\"", ""));//成交额(万元)
                }
               

                //本次涨幅
                double real_zf = GPUtil.getRealDpZf(dp);
                dp.real_zf = real_zf;
                
                dpList.Add(dp);
            }

            return dpList;
        }