private void biForecast_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Stop = false; this.siStatus.Caption = "<b>Autorizing on walletinvestor.com</b>"; WalletInvestorPortalHelper helper = new WalletInvestorPortalHelper(); helper.Enter("*****@*****.**", "ejv8iU93bdBnRnG"); if (!helper.WaitUntil(30000, () => helper.State == PortalState.AutorizationDone)) { XtraMessageBox.Show("Error autorizing on walletinvestor.com"); return; } Registered = false; foreach (WalletInvestorDataItem item in Items) { this.siStatus.Caption = "<b>Update forecast for " + item.Name + "</b>"; if (GetForecastFor(item, helper)) { this.gridView1.RefreshRow(this.gridView1.GetRowHandle(Items.IndexOf(item))); } Application.DoEvents(); if (Stop) { break; } } helper.Dispose(); if (Stop) { this.siStatus.Caption = "<b>Interrupted</b>"; } else { this.siStatus.Caption = "<b>Done</b>"; } }
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))); }