bool IWalletInvestorForecastProvider.UpdateForecast(WalletInvestorForecastStrategy strategy, WalletInvestorDataItem item) { if (Helper == null) { return(false); } return(GetForecastFor(strategy, item)); }
protected bool GetForecastFor(WalletInvestorForecastStrategy strategy, WalletInvestorDataItem item) { PortalClient wc = new PortalClient(Helper.Chromium); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?currency={0}", item.Name)); if (data == null) { return(false); } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(new MemoryStream(data)); HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed"); if (node == null) { return(false); } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); if (rows.Count == 0) { return(false); } for (int ni = 0; ni < rows.Count; ni++) { HtmlNode row = rows[ni]; HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0"); HtmlNode forecast14 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1"); HtmlNode forecast3Month = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); try { string nameText = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); if (item.Name != nameText) { continue; } item.Forecast14Day = Convert.ToDouble(strategy.CorrectString(forecast14.Element("a").InnerText)); item.Forecast3Month = Convert.ToDouble(strategy.CorrectString(forecast3Month.Element("a").InnerText)); if (item.Forecast14Day < strategy.Day14MinPercent || item.Forecast3Month < strategy.Month3MinPercent) { return(true); } Get7DayForecastFor(item, name.Element("a").GetAttributeValue("href", "")); return(true); } catch (Exception) { continue; } } return(false); }
bool IWalletInvestorForecastProvider.Initialize(WalletInvestorForecastStrategy strategy) { if (Helper != null) { return(true); } WalletInvestorPortalHelper helper = new WalletInvestorPortalHelper(); helper.Enter(strategy.Login, strategy.Password); if (!helper.WaitUntil(30000, () => helper.State == PortalState.AutorizationDone)) { return(false); } Helper = helper; return(true); }