public List<ParserItem> parse() { // write parse this string response = getHTMLresponse(); if (response == null) return cutParsedItems(parsedItems); if (parsedItems.Count > 0) parsedItems.Clear(); RegexOptions regOptions = RegexOptions.Singleline; Regex itemRegex = new Regex(mItemPattern,regOptions); Regex newsTimeRegex = new Regex(mNewsTimePattern,regOptions); Regex symbolRegex = new Regex(mSymbolPattern,regOptions); Regex volatileRegex = new Regex(mVolatilePattern,regOptions); Regex newsRegex = new Regex(mNewsPattern,regOptions); Regex actualRegex = new Regex(mActualPattern, regOptions); Regex forecastRegex = new Regex(mForecastPattern, regOptions); Regex previousRegex = new Regex(mPreviousPattern, regOptions); MatchCollection items = itemRegex.Matches(response); File.WriteAllText("logw.txt", response); Console.WriteLine(items.Count + " items(news Blocks)"); foreach(Match item in items) { ParserItem parserItem = new ParserItem(); if (newsTimeRegex.IsMatch(item.Value)) { parserItem.time = newsTimeRegex.Match(item.Value).Value; } if (symbolRegex.IsMatch(item.Value)) { parserItem.symbol = symbolRegex.Match(item.Value).Value; } if (volatileRegex.IsMatch(item.Value)) { parserItem.volatiled = volatileRegex.Match(item.Value).Value; } if (newsRegex.IsMatch(item.Value)) { parserItem.news = newsRegex.Match(item.Value).Value; } if (actualRegex.IsMatch(item.Value)) { parserItem.actual = actualRegex.Match(item.Value).Value; } if (forecastRegex.IsMatch(item.Value)) { parserItem.forecast = forecastRegex.Match(item.Value).Value; } if (previousRegex.IsMatch(item.Value)) { parserItem.previous = previousRegex.Match(item.Value).Value; } if (parserItem.symbol != null && parserItem.time != null) { parsedItems.Add(parserItem); } } return cutParsedItems(parsedItems); }
// Самая главная функция, основное распределение идет в ней !! private string getMidVolatileAdvise(ParserItem item) { StringBuilder advise = new StringBuilder(); // Отдаёт распарсенные значения из ParserItem, если значения нет, присваивается - MAX_VALUE; double prev = item.getPrev(); double act = item.getAct(); double fore = item.getFore(); if (item.used) { return advise.ToString(); } if (prev == Double.MaxValue) { return advise.ToString(); } if (act == Double.MaxValue) { return advise.ToString(); } if (fore == Double.MaxValue) { if (Math.Abs(act - prev) < 0.0000001) { advise.Append("NO ACTION"); } else if (act < prev) { advise.Append("SELL ACTION"); } else { advise.Append("BUY ACTION"); } } else { if (Math.Abs(fore - act) < 0.0000001) { if (Math.Abs(act - prev) < 0.0000001) { advise.Append("NO ACTION"); } else if (act < prev) { advise.Append("SELL ACTION"); } else { advise.Append("BUY ACTION"); } } else if (act < fore) { advise.Append("SELL ACTION"); } else { advise.Append("BUY ACTION"); } } if (item.reverse) { if (advise.ToString().Contains("BUY")) { advise.Replace("BUY", "SELL"); } else if (advise.ToString().Contains("SELL")) { advise.Replace("SELL", "BUY"); } } item.used = true; return advise.ToString().Insert(0, "MID "); }
private string getHighVolatileAdvise(ParserItem item) { StringBuilder advise = new StringBuilder(); if (!item.used) { advise.Append("NO ACTION"); } return advise.ToString(); }
private string getLowVolatileAdvise(ParserItem item) { return getMidVolatileAdvise(item).Replace("MID", "LOW"); }
private bool existActual(ParserItem item) { string actual = item.actual; actual.Replace(",", "."); try { Double.Parse(actual); return true; } catch (Exception exc) { return false; } return false; }