private void DownloadDetailedForecast(string coin) { PortalClient wc = new PortalClient(); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?currency={0}", coin)); if (data == null) { return; } 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; } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); if (rows.Count == 0) { return; } foreach (HtmlNode row in rows) { 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 { WalletInvestorDataItem item = new WalletInvestorDataItem() { Name = coin }; string nameText = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); if (item.Name != nameText) { continue; } item.Description = name.InnerText.Remove(name.InnerText.Length - nameText.Length); item.Forecast14Day = Convert.ToDouble(CorrectString(forecast14.Element("a").InnerText)); item.Forecast3Month = Convert.ToDouble(CorrectString(forecast3Month.Element("a").InnerText)); WiItems.Add(item); } catch (Exception) { continue; } } }
protected virtual void UpdateCombined() { bool union = this.bcMode.Checked; List <WalletInvestorDataItem> wi = WiItems.Where(i => i.Match).ToList(); List <CoinPredictorDataItem> cp = CpItems.Where(i => i.Match).ToList(); List <string> names = new List <string>(); for (int ii = 0; ii < wi.Count; ii++) { WalletInvestorDataItem item = wi[ii]; if (union || cp.FirstOrDefault(i => i.Name == item.Name) != null) { names.Add(item.Name); } } for (int ii = 0; ii < cp.Count; ii++) { CoinPredictorDataItem item = cp[ii]; if (names.Contains(item.Name)) { continue; } if (union || wi.FirstOrDefault(i => i.Name == item.Name) != null) { names.Add(item.Name); } } List <CombinedData> res = new List <CombinedData>(); for (int ni = 0; ni < names.Count; ni++) { string name = names[ni]; CombinedData data = new CombinedData(); WalletInvestorDataItem w = wi.FirstOrDefault(i => i.Name == name); CoinPredictorDataItem c = cp.FirstOrDefault(i => i.Name == name); string nameItem = w == null ? c.Name : w.Name; data.Name = nameItem; if (w != null) { data.Wi7Day = w.Forecast7Day; data.Wi14Day = w.Forecast14Day; data.Wi3Month = w.Forecast3Month; data.WiMatch = w.Match; } if (c != null) { data.Cp1Day = c.Forecast1Day; data.Cp7Day = c.Forecast7Day; data.Cp4Week = c.Forecast4Week; data.CpMatch = c.Match; } if (union) { data.Match = data.WiMatch | data.CpMatch; } else { data.Match = data.WiMatch & data.CpMatch; } res.Add(data); } this.combinedDataBindingSource.DataSource = res; }
protected void GetForecasts() { Stop = false; var handle = SplashScreenManager.ShowOverlayForm(this.gridControl); double percent = Settings.Min24HourChange; for (int i = 1; i < 1000; i++) { if (Stop) { break; } this.siStatus.Caption = "<b>Downloading page " + i + "</b>"; Application.DoEvents(); WebClient wc = new WebClient(); string adress = string.Format("https://walletinvestor.com/forecast?sort=-forecast_percent_change_14d&page={0}&per-page=100", i); byte[] data = wc.DownloadData(adress); 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; } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); if (rows.Count == 0) { break; } bool finished = false; for (int ri = 0; ri < rows.Count; ri++) { HtmlNode row = rows[ri]; HtmlNode day14Change = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1"); string changeString = CorrectString(day14Change.InnerText); double change = Convert.ToDouble(CorrectString(changeString)); HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0"); try { HtmlNode nameDetail = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail"); string nameString = nameDetail.InnerText.Trim(); WalletInvestorDataItem item = WiItems.FirstOrDefault(it => it.Name == nameString); if (item == null) { continue; } item.Forecast14Day = change; HtmlNode month3Change = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); item.Forecast3Month = Convert.ToDouble(CorrectString(month3Change.Element("a").InnerText)); if (change < Settings.Min14DayChange) { finished = true; break; } } catch (Exception) { continue; } } if (Stop) { this.siStatus.Caption = "<b>Interrupted<b>"; } else { this.siStatus.Caption = "<b>Done<b>"; } this.gridView1.RefreshData(); Application.DoEvents(); if (finished) { break; } } SplashScreenManager.CloseOverlayForm(handle); }
private void DownloadWalletInvestorForecast() { var handle = SplashScreenManager.ShowOverlayForm(this.gridControl); this.siStatus.Caption = "<b>Connect Binance</b>"; Application.DoEvents(); if (!BinanceExchange.Default.Connect()) { XtraMessageBox.Show("Failed connect Binance"); this.siStatus.Caption = "<b>Failed connect Binance</b>"; SplashScreenManager.CloseOverlayForm(handle); } Stop = false; this.siStatus.Caption = "<b>Autorizing on walletinvestor.com</b>"; Application.DoEvents(); WalletInvestorPortalHelper helper = new WalletInvestorPortalHelper(); helper.Enter(InvictusSettings.Default.Login, InvictusSettings.Default.Password); if (!Registered && !helper.WaitUntil(Settings.AutorizationOperationWaitTimeInSeconds * 1000, () => helper.State == PortalState.AutorizationDone)) { XtraMessageBox.Show("Error autorizing on walletinvestor.com"); this.siStatus.Caption = "<b>Error autorizing on walletinvestor.com</b>"; SplashScreenManager.CloseOverlayForm(handle); helper.Dispose(); return; } Registered = true; List <WalletInvestorDataItem> list = new List <WalletInvestorDataItem>(); WiItems = list; //List<Ticker> double percent = Settings.Min24HourChange; for (int i = 1; i < 1000; i++) { if (Stop) { break; } this.siStatus.Caption = "<b>Downloading page " + i + "</b>"; Application.DoEvents(); WebClient wc = new WebClient(); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?sort=-forecast_percent_change_14d&page={0}&per-page=100", i)); if (data == null || data.Length == 0) { XtraMessageBox.Show("Error downloading page from walletinvestor.com"); this.siStatus.Caption = "<b>Error downloading page from walletinvestor.com</b>"; SplashScreenManager.CloseOverlayForm(handle); helper.Dispose(); return; } 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) { XtraMessageBox.Show("It seems that walletinvestor forecast page layout is changed. Please contact developer"); SplashScreenManager.CloseOverlayForm(handle); helper.Dispose(); this.siStatus.Caption = "<b>Error!</b>"; return; } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); bool finished = false; for (int ri = 0; ri < rows.Count; ri++) { HtmlNode row = rows[ri]; HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0"); try { string nameText = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); WalletInvestorDataItem item = new WalletInvestorDataItem(); string description = name.InnerText.Remove(name.InnerText.Length - nameText.Length); item.Name = nameText; item.Description = description; Ticker ticker = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name && t.BaseCurrency == "BTC"); HtmlNode forecast14 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1"); item.Forecast14Day = Convert.ToDouble(CorrectString(forecast14.Element("a").InnerText)); if (item.Forecast14Day < Settings.Min14DayChange) { finished = true; break; } if (ticker == null) { continue; } item.BinanceLink = ticker.WebPageAddress; HtmlNode forecast3Month = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); item.Forecast3Month = Convert.ToDouble(CorrectString(forecast3Month.Element("a").InnerText)); item.ForecastLink = name.Element("a").GetAttributeValue("href", ""); item.ForecastLink2 = string.Format("https://walletinvestor.com/forecast?currency={0}", item.Name); name.Element("a").GetAttributeValue("href", ""); list.Add(item); } catch (Exception) { XtraMessageBox.Show("An error was detected when parsing page. Please contact developer"); SplashScreenManager.CloseOverlayForm(handle); this.siStatus.Caption = "<b>Error!</b>"; continue; } } this.gridView1.RefreshData(); Application.DoEvents(); if (finished) { break; } } this.siStatus.Caption = "<b>Downloading 7-day forecast</b>"; this.beProgress.EditValue = 0; this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; Application.DoEvents(); int itemIndex = 0; foreach (WalletInvestorDataItem item in WiItems) { if (!Get7DayForecastFor(item, item.ForecastLink, helper)) { XtraMessageBox.Show("Error parsing 7-day forecast page. Please contact developer"); this.siStatus.Caption = "<b>Error!</b>"; helper.Dispose(); this.gridView1.RefreshData(); SplashScreenManager.CloseOverlayForm(handle); return; } item.Match = item.Forecast7Day >= Settings.Min7DaysChange && item.Forecast14Day >= Settings.Min14DayChange && item.Forecast3Month >= Settings.Min3MonthChange; this.beProgress.EditValue = (int)((double)itemIndex / WiItems.Count * 100); itemIndex++; Application.DoEvents(); if (Stop) { break; } } this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; this.siStatus.Caption = Stop? "<b>Interrupted<b>": "<b>Done<b>"; this.gridView1.RefreshData(); helper.Dispose(); SplashScreenManager.CloseOverlayForm(handle); UpdateCombined(); XtraMessageBox.Show(string.Format("Found {0} items matched criteria", WiItems.Count(i => i.Match))); }