/// <summary> /// Get trading information about "(Main Board) up to day" . /// </summary> /// <returns>a instance of the Class TradingInfo which is about the Main01_10 trading News Info.</returns> public TradingInfo GetMain01_10TradingInfo() { string url = configObj.MainBoardUri; // "/eng/stat/smstat/ssturnover/ncms/ASHTMAIN.HTM"; // url = MiscUtil.UrlCombine(configObj.BASE_URI, url); TradingInfo main01_10TradingInfo = new TradingInfo(); main01_10TradingInfo.StockList = new List <StockInfo>(); List <string> valueList = new List <string>(); string tradingNewsInfo = string.Empty; string dateStr = DateTime.Now.ToString("dddd dd/MM/yyyy"); main01_10TradingInfo.DateStr = string.Format("Recorded as of {0} 04:00 pm :-", dateStr); var htmlDoc = WebClientUtil.GetHtmlDocument(url, 180000); tradingNewsInfo = htmlDoc.DocumentNode.SelectSingleNode("//body/pre/font").InnerText; using (StringReader sr = new StringReader(tradingNewsInfo)) { string line; while ((line = sr.ReadLine()) != null) { //Parse the stock info string[] frags = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); int ric = 0; if (frags.Length == 4 && int.TryParse(frags[0].Trim(), out ric)) { StockInfo stockInfo = new StockInfo(); stockInfo.Ric = string.Format("<{0}.HK>", ric.ToString("D4")); stockInfo.StockName = frags[1].Trim(); stockInfo.Shares = frags[2].Trim(); stockInfo.Turnover = frags[3].Trim(); main01_10TradingInfo.StockList.Add(stockInfo); continue; } else if (frags.Length == 4 && !int.TryParse(frags[0].Trim(), out ric)) { Regex regExpression = new Regex("[0-9]+"); Match match = regExpression.Match(frags[0].Trim()); if (match.Success) { StockInfo stockInfo = new StockInfo(); stockInfo.Ric = string.Format("<{0}.HK>", match.Value); stockInfo.StockName = frags[1].Trim(); stockInfo.Shares = frags[2].Trim(); stockInfo.Turnover = frags[3].Trim(); main01_10TradingInfo.StockList.Add(stockInfo); continue; } } frags = line.Split(':'); if (frags.Length == 2 && frags[1].Trim() != "") { valueList.Add(line.Trim()); } } //Parse to get the summary info of Main Board if (valueList != null && valueList.Count > 0) { main01_10TradingInfo.DesignatedSecuritiesRecordingSum = valueList[1]; main01_10TradingInfo.DesignatedSharesShortSoldSum = valueList[2]; main01_10TradingInfo.DesignatedShortSellTurnoverShares = valueList[3]; main01_10TradingInfo.DesignatedShortSellTurnoverValue = valueList[4]; main01_10TradingInfo.HKDTurnoverValue = valueList[5]; } } return(main01_10TradingInfo); }
/// <summary> /// Get GEM trading News Info. /// </summary> /// <param name="uri">the uri of the source data which is a html page.</param> /// <returns>a instance of the Class TradingInfo which is about the GEM trading News Info.</returns> public TradingInfo GetGemTradingInfo(string uri) { HtmlAgilityPack.HtmlDocument htmlDoc = null; htmlDoc = WebClientUtil.GetHtmlDocument(uri, 180000); TradingInfo gemTradingInfo = new TradingInfo(); gemTradingInfo.StockList = new List <StockInfo>(); List <string> valueList = new List <string>(); string dateStr = DateTime.Now.ToString("dddd dd/MM/yyyy"); gemTradingInfo.DateStr = string.Format("Recorded as of {0} 04:00 pm :-", dateStr); //Get the trading news information string gemTradingNewsInfo = htmlDoc.DocumentNode.SelectSingleNode("//body/pre/font").InnerText; //Parse and get the required information if (!IsNewsExist(gemTradingNewsInfo)) { gemTradingInfo.StockList = null; } using (StringReader sr = new StringReader(gemTradingNewsInfo)) { string line; while ((line = sr.ReadLine()) != null) { string[] frags = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); int ric = 0; if (frags.Length == 4 && int.TryParse(frags[0].Trim(), out ric)) { StockInfo stockInfo = new StockInfo(); stockInfo.Ric = string.Format("<{0}.HK>", ric.ToString("D4")); stockInfo.StockName = frags[1].Trim(); stockInfo.Shares = frags[2].Trim(); stockInfo.Turnover = frags[3].Trim(); gemTradingInfo.StockList.Add(stockInfo); continue; } frags = line.Split(':'); if (frags.Length == 2 && frags[1].Trim() != "") { valueList.Add(line.Trim()); } } } //Parse to get the summary info of Main Board if (valueList != null && valueList.Count > 0) { gemTradingInfo.DesignatedSecuritiesRecordingSum = valueList[1]; gemTradingInfo.DesignatedSharesShortSoldSum = valueList[2]; gemTradingInfo.DesignatedShortSellTurnoverShares = valueList[3]; gemTradingInfo.DesignatedShortSellTurnoverValue = valueList[4]; if (valueList[5].Contains("Short Selling Turnover Total Value ($) : HKD ")) { gemTradingInfo.HKDTurnoverValue = valueList[5]; } } return(gemTradingInfo); }