/// <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 = Get(url); } return(result); }
/// <summary> /// 根据代码获取新浪历史数据的字符串 /// </summary> /// <param name="code"></param> /// <returns></returns> public static String GetSinaHistoryDatasStrByCode(String code, int cycle) { String url = "https://quotes.sina.cn/cn/api/json_v2.php/CN_MarketDataService.getKLineData?symbol=" + FCStrEx.convertDBCodeToSinaCode(code) + "&scale=" + cycle.ToString() + "&ma=no&datalen=1023"; return(Get(url)); }
/// <summary> /// 根据字符串获取新浪的最新数据 /// </summary> /// <param name="str">数据字符串</param> /// <param name="formatType">格式</param> /// <param name="data">最新数据</param> /// <returns>状态</returns> public static int GetLatestDataBySinaStr(String str, int formatType, ref SecurityLatestData data) { //分析数据 String date = ""; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); int strLen2 = strs2.Length; bool szIndex = false; for (int j = 0; j < strLen2; j++) { String str2 = strs2[j]; switch (j) { case 0: data.m_code = FCStrEx.convertSinaCodeToDBCode(str2); if (data.m_code.StartsWith("399")) { szIndex = true; } break; case 1: { data.m_open = Convert.ToDouble(str2); break; } case 2: { data.m_lastClose = Convert.ToDouble(str2); break; } case 3: { data.m_close = Convert.ToDouble(str2); break; } case 4: { data.m_high = Convert.ToDouble(str2); break; } case 5: { data.m_low = Convert.ToDouble(str2); break; } case 8: { data.m_volume = Convert.ToDouble(str2); if (szIndex) { data.m_volume /= 100; } break; } case 9: { data.m_amount = Convert.ToDouble(str2); break; } case 10: { if (formatType == 0) { data.m_buyVolume1 = (int)Convert.ToDouble(str2); } break; } case 11: { if (formatType == 0) { data.m_buyPrice1 = Convert.ToDouble(str2); } break; } case 12: { if (formatType == 0) { data.m_buyVolume2 = (int)Convert.ToDouble(str2); } break; } case 13: { if (formatType == 0) { data.m_buyPrice2 = Convert.ToDouble(str2); } break; } case 14: { if (formatType == 0) { data.m_buyVolume3 = (int)Convert.ToDouble(str2); } break; } case 15: { if (formatType == 0) { data.m_buyPrice3 = Convert.ToDouble(str2); } break; } case 16: { if (formatType == 0) { data.m_buyVolume4 = (int)Convert.ToDouble(str2); } break; } case 17: { if (formatType == 0) { data.m_buyPrice4 = Convert.ToDouble(str2); } break; } case 18: { if (formatType == 0) { data.m_buyVolume5 = (int)Convert.ToDouble(str2); } break; } case 19: { if (formatType == 0) { data.m_buyPrice5 = Convert.ToDouble(str2); } break; } case 20: { if (formatType == 0) { data.m_sellVolume1 = (int)Convert.ToDouble(str2); } break; } case 21: { if (formatType == 0) { data.m_sellPrice1 = Convert.ToDouble(str2); } break; } case 22: { if (formatType == 0) { data.m_sellVolume2 = (int)Convert.ToDouble(str2); } break; } case 23: { if (formatType == 0) { data.m_sellPrice2 = Convert.ToDouble(str2); } break; } case 24: { if (formatType == 0) { data.m_sellVolume3 = (int)Convert.ToDouble(str2); } break; } case 25: { if (formatType == 0) { data.m_sellPrice3 = Convert.ToDouble(str2); } break; } case 26: { if (formatType == 0) { data.m_sellVolume4 = (int)Convert.ToDouble(str2); } break; } case 27: { if (formatType == 0) { data.m_sellPrice4 = Convert.ToDouble(str2); } break; } case 28: { if (formatType == 0) { data.m_sellVolume5 = (int)Convert.ToDouble(str2); } break; } case 29: { if (formatType == 0) { data.m_sellPrice5 = Convert.ToDouble(str2); } break; } case 30: date = str2; break; case 31: date += " " + str2; break; } } //获取时间 if (date != null && date.Length > 0) { DateTime dateTime = Convert.ToDateTime(date); data.m_date = (dateTime - new DateTime(1970, 1, 1)).TotalSeconds; //data.m_date = FCTran.GetDateNum(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, 0); } //价格修正 if (data.m_close != 0) { if (data.m_open == 0) { data.m_open = data.m_close; } if (data.m_high == 0) { data.m_high = data.m_close; } if (data.m_low == 0) { data.m_low = data.m_close; } } return(0); }