public CAllStockCode() { // LST CODE string sdata = GetHttpData.GetUrltoHtml(GetHttpData.libCode); JsonData jdata = JsonMapper.ToObject(sdata); JsonData jdata2 = jdata["list"]; for (int i = 0; i < jdata2.Count; ++i) { string code = (string)jdata2[i]["CODE"]; lstCode.Add(code); if (code.StartsWith("06")) { sh_code.Add(code); } else if (code.StartsWith("1002")) { sz_code_s.Add(code); } else if (code.StartsWith("130")) { sz_code_c.Add(code); } else { sz_code_a.Add(code); } } }
static string GetCodeData(string code, string beginTime, string curTime) { try { string url = string.Format(GetHttpData.urlFormat, "", code, beginTime, curTime); string contents = GetHttpData.GetUrltoHtml(url, "GB18030"); string[] lines = contents.Split('\n'); // 记录数过滤。。。 if (lines.Length <= 3) { return(null); } CStockContents sc = new CStockContents(); for (int j = lines.Length - 1; j > 0; --j) { // 过滤停。。。 if (lines[j].Contains("None,") || lines[j] == "") { continue; } CLineContents lc = new CLineContents(lines[j]); sc.Push(lc); if (j == 1) { CLineContents lcTmp = GetRealtimeData(code); if (lcTmp != null) { sc.Push(lcTmp); } } } string res = sc.GetResult(); if (res != null || res != "") { return(res); } } catch (Exception ex) { Console.WriteLine(ex.ToString() + "\n" + code); } return(null); }
static CLineContents GetRealtimeData(string code) { DateTime dt = new DateTime(DateTime.Now.Ticks); // dapan is out data after 17,maybe, but gegu delay a day; if (dt.DayOfWeek != DayOfWeek.Sunday && dt.DayOfWeek != DayOfWeek.Saturday && dt.Hour > 9 && dt.Hour < 15) { string nowData = GetHttpData.GetUrltoHtml(string.Format(GetHttpData.nowFormat, code)); int start = nowData.LastIndexOf('{'); nowData = nowData.Substring(start, nowData.IndexOf('}') - start + 1); JsonData tmpData = JsonMapper.ToObject(nowData); CLineContents lc2 = new CLineContents(); try { lc2.time = (string)tmpData["time"]; lc2.code = (string)tmpData["code"]; lc2.name = (string)tmpData["name"]; lc2.last = (float)((double)tmpData["price"]); lc2.high = (float)(double)tmpData["high"]; lc2.low = (float)(double)tmpData["low"]; lc2.start = (float)(double)tmpData["open"]; lc2.yes_last = (float)((double)tmpData["yestclose"]); lc2.price = (float)(double)tmpData["updown"]; lc2.rate = (float)((double)tmpData["percent"] * 100); lc2.chg_rate = 0; lc2.chg_num = (int)tmpData["volume"]; //lc2.chg_value = (float)(double)tmpData["turnover"]; lc2.total = 0; lc2.total_on = 0; } catch (Exception e) { Console.WriteLine(e.ToString() + "\n" + nowData); } if (lc2.start >= float.Epsilon) { return(lc2); } } return(null); }