Esempio n. 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(FCStrEx.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 = FCHttpGetService.get(url);
            }
            return(result);
        }
Esempio n. 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 + FCStrEx.convertDBCodeToFileName(code);
                if (!FCFile.isFileExist(fileName))
                {
                    fileName = m_newFileDir + FCStrEx.convertDBCodeToSinaCode(code).ToUpper() + ".txt";
                }
                if (FCFile.isFileExist(fileName))
                {
                    String text = "";
                    FCFile.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;
                    }
                }
            }
        }
Esempio n. 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\\" + FCStrEx.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;
             }
         }
     }
 }