Пример #1
0
        /// <summary>
        /// 根据股票代码获取新浪最新数据
        /// </summary>
        /// <param name="codes">股票代码列表</param>
        /// <returns>字符串</returns>
        public static String GetSinaLatestDatasStrByCodes(String codes)
        {
            String[]      strs      = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int           strLen    = strs.Length;
            List <String> sinaCodes = new List <String>();
            List <String> dcCodes   = new List <String>();

            for (int i = 0; i < strLen; i++)
            {
                String postCode = strs[i];
                sinaCodes.Add(CStrA.ConvertDBCodeToSinaCode(postCode));
            }
            String requestCode   = "";
            int    sinaCodesSize = sinaCodes.Count;

            for (int i = 0; i < sinaCodesSize; i++)
            {
                String postCode = sinaCodes[i];
                requestCode += postCode;
                if (i != strLen - 1)
                {
                    requestCode += ",";
                }
            }
            String result = "";

            if (sinaCodesSize > 0)
            {
                String url = "http://hq.sinajs.cn/list=" + requestCode.ToLower();
                result = HttpGetService.Get(url);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 获取分时数据
        /// </summary>
        public static void GetMinuteDatas()
        {
            if (m_minuteDatas.Count > 0)
            {
                return;
            }
            String appPath = DataCenter.GetAppPath();

            foreach (String code in m_codedMap.Keys)
            {
                String fileName = m_newFileDir + CStrA.ConvertDBCodeToFileName(code);
                if (!CFileA.IsFileExist(fileName))
                {
                    fileName = m_newFileDir + CStrA.ConvertDBCodeToSinaCode(code).ToUpper() + ".txt";
                }
                if (CFileA.IsFileExist(fileName))
                {
                    String text = "";
                    CFileA.Read(fileName, ref text);
                    List <SecurityData> datas = new List <SecurityData>();
                    StockService.GetHistoryDatasByMinuteStr(text, datas);
                    if (datas.Count > 0)
                    {
                        int rindex   = 0;
                        int dataSize = datas.Count;
                        while (rindex < dataSize)
                        {
                            SecurityData d = datas[rindex];
                            if (rindex == 0)
                            {
                                d.m_avgPrice = d.m_close;
                            }
                            else
                            {
                                SecurityData ld = datas[rindex - 1];
                                d.m_avgPrice = (ld.m_avgPrice * rindex + d.m_close) / (rindex + 1);
                            }
                            rindex++;
                        }
                        m_minuteDatas[code] = datas;
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// 加载历史数据
 /// </summary>
 /// <param name="history"></param>
 public static void LoadHistoryDatas()
 {
     if (m_historyDatas.Count > 0)
     {
         return;
     }
     foreach (String code in m_codedMap.Keys)
     {
         String fileName = DataCenter.GetAppPath() + "\\day\\" + CStrA.ConvertDBCodeToSinaCode(code).ToUpper() + ".txt";
         if (File.Exists(fileName))
         {
             StreamReader        sra   = new StreamReader(fileName, Encoding.Default);
             String              text  = sra.ReadToEnd();
             List <SecurityData> datas = new List <SecurityData>();
             StockService.GetHistoryDatasByTdxStr(text, datas);
             if (datas.Count > 0)
             {
                 m_historyDatas[code] = datas;
             }
         }
     }
 }