Ejemplo n.º 1
0
        /// <summary>
        /// 获取股票名称
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetStockNameByJuhe(string code)
        {
            string name       = "";
            object stock_name = CacheHelper.Get(code);

            if (stock_name != null)
            {
                name = stock_name.ToString();
            }
            else
            {
                string stock_code = "";
                if (code.Trim().Length == 6)
                {
                    if (Utils.subStr(code, 0, 1) == "6")
                    {
                        //上证A、B股
                        stock_code = "sh" + code;
                    }
                    else
                    {
                        //沪深A股-深圳A、B股
                        stock_code = "sz" + code;
                    }
                }
                //1.沪深股市
                var parameters1 = new Dictionary <string, string>();
                parameters1.Add("gid", stock_code);           //股票编号,上海股市以sh开头,深圳股市以sz开头如:sh601009
                parameters1.Add("key", AppKeys.JUHE_API_KEY); //你申请的key
                name = Utils.GetHttpValue(sendPost(AppKeys.JUHE_API_URL, parameters1, "get"), "\"name\":\"", "\",\"nowPri\"");
                CacheHelper.Insert(code, name, 1440);
            }
            return(name);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取股票数据接口
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetStockDataByJuhe(string code)
        {
            string stock_code = "";

            if (code.Trim().Length == 6)
            {
                if (Utils.subStr(code, 0, 1) == "6")
                {
                    //上证A、B股
                    stock_code = "sh" + code;
                }
                else
                {
                    //沪深A股-深圳A、B股
                    stock_code = "sz" + code;
                }
            }
            //1.沪深股市
            var parameters1 = new Dictionary <string, string>();

            parameters1.Add("gid", stock_code);           //股票编号,上海股市以sh开头,深圳股市以sz开头如:sh601009
            parameters1.Add("key", AppKeys.JUHE_API_KEY); //你申请的key
            StringBuilder sb = new StringBuilder();
            Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(sendPost(AppKeys.JUHE_API_URL, parameters1, "get"));

            if (dic["reason"].ToString() == "SUCCESSED!")
            {
                ArrayList arr = (ArrayList)dic["result"];
                Dictionary <string, object> arrlist = (Dictionary <string, object>)arr[0];
                Dictionary <string, object> str     = (Dictionary <string, object>)arrlist["data"];
                sb.Append(str["name"] + ","            /*股票名称*/
                          + str["todayStartPri"] + "," /*今日开盘价*/
                          + str["yestodEndPri"] + ","  /*昨日收盘价*/
                          + str["nowPri"] + ","        /*当前价格*/
                          + str["todayMax"] + ","      /*今日最高价*/
                          + str["todayMin"] + ","      /*今日最低价*/
                          + str["buyOnePri"] + ","     /*竞买价,即“买一”报价;*/
                          + str["sellOnePri"] + ","    /*竞卖价,即“卖一”报价;*/
                          + str["traNumber"] + ","     /*成交量*/
                          + str["traAmount"] + ","     /*成交金额*/
                          + str["buyOne"] + ","        /*买一*/
                          + str["buyOnePri"] + ","     /*买一报价*/
                          + str["buyTwo"] + ","
                          + str["buyTwoPri"] + ","
                          + str["buyThree"] + ","
                          + str["buyThreePri"] + ","
                          + str["buyFour"] + ","
                          + str["buyFourPri"] + ","
                          + str["buyFive"] + ","
                          + str["buyFivePri"] + ","
                          + str["sellOne"] + ","    /*卖一*/
                          + str["sellOnePri"] + "," /*卖一报价*/
                          + str["sellTwo"] + ","
                          + str["sellTwoPri"] + ","
                          + str["sellThree"] + ","
                          + str["sellThreePri"] + ","
                          + str["sellFour"] + ","
                          + str["sellFourPri"] + ","
                          + str["sellFive"] + ","
                          + str["sellFivePri"] + ","
                          + str["date"] + ","
                          + str["time"]);
            }
            return(sb.ToString());
        }