protected virtual bool Get7DayForecastFor(WalletInvestorDataItem item, string address, WalletInvestorPortalHelper helper) { helper.State = PortalState.LoadPage; helper.Chromium.Load(address); if (!helper.WaitUntil(Settings.AutorizationOperationWaitTimeInSeconds * 1000, () => helper.State == PortalState.PageLoaded)) { return(false); } item.ForecastLink = address; string text = helper.GetElementByIdContent("seven-day-forecast-desc"); if (text == "Get It Now!") { if (!helper.ClickOnObjectById("seven-day-forecast-desc")) { return(false); } if (!helper.WaitUntil(Settings.AutorizationOperationWaitTimeInSeconds * 1000, () => helper.FindElementById("usersubscriberforecast-email"))) { return(false); } if (!helper.SetElementValueById("usersubscriberforecast-email", "'" + helper.Login + "'")) { return(false); } if (!helper.ClickOnObjectById("usersubscriberforecast-agreement")) { return(false); } if (!helper.ClickOnObjectByClass("btn btn-success")) { return(false); } if (helper.WaitUntil(10000, () => helper.CheckElementByClassNameContent("swal2-confirm swal2-styled", "OK") == true)) { XtraMessageBox.Show("You did not unlock all of our 7 days forecasts for this E-mail: " + helper.Login + ". Please go to your mail client, find the e-mail from walletinvestor and active your e-mail by click on the link"); } helper.Wait(10000); } try { text = helper.GetElementByClassNameContent("number"); string[] items = text.Split(' '); item.LastPrice = Convert.ToDouble(RemoveGlyph(items[0])); text = helper.GetElementByIdContent("seven-day-forecast-desc"); items = text.Split(' '); if (items.Length != 2) { return(false); } item.Forecast7Day = (Convert.ToDouble(items[0].Trim()) - item.LastPrice) / item.LastPrice * 100; } catch (Exception) { return(false); } return(true); }
protected virtual bool Get7DayForecastFor(WalletInvestorDataItem item, string address, WalletInvestorPortalHelper helper) { helper.State = PortalState.LoadPage; helper.Chromium.Load(address); if (!helper.WaitUntil(5000, () => helper.State == PortalState.PageLoaded)) { return(false); } string text = helper.GetElementByIdContent("seven-day-forecast-desc"); if (text == "Get It Now!") { if (!helper.ClickOnObjectById("seven-day-forecast-desc")) { return(false); } if (!helper.WaitUntil(10000, () => helper.FindElementById("usersubscriberforecast-email"))) { return(false); } if (!helper.SetElementValueById("usersubscriberforecast-email", "'" + helper.Login + "'")) { return(false); } if (!helper.ClickOnObjectById("usersubscriberforecast-agreement")) { return(false); } if (!helper.ClickOnObjectByClass("btn btn-success")) { return(false); } helper.Wait(2000); } Registered = true; try { text = helper.GetElementByIdContent("seven-day-forecast-desc"); string[] items = text.Split(' '); if (items.Length != 2) { return(false); } item.Forecast7Day = (Convert.ToDouble(items[0].Trim()) - item.LastPrice) / item.LastPrice * 100; } catch (Exception) { return(false); } return(true); }
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); }
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))); }