private void Log(WalletInvestorDataItem item) { string text = string.Format("found: {0} with 24h = {1:0.###}% 7d = {2:0.###}% 3m = {3:0.###}%", item.Name, item.Change24, item.Forecast7Day, item.Forecast14Day, item.Forecast3Month); TelegramBot.Default.SendNotification(text, ChatId); Log(LogType.Success, text, 0, 0, StrategyOperation.Connect); }
protected virtual void CheckUpdateItems() { Log(LogType.Log, "start pull items data from walletinvestor.com", 0, 0, StrategyOperation.Connect); List <WalletInvestorDataItem> list = new List <WalletInvestorDataItem>(); double percent = Hour24MinPercent; for (int i = 1; i < 1000; i++) { WebClient wc = new WebClient(); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/?sort=-percent_change_24h&page={0}&per-page=100", i)); 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 kv-table-wrap"); 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 ni = 0; ni < rows.Count; ni++) { HtmlNode row = rows[ni]; HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); HtmlNode prices = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "3"); HtmlNode change24 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "4"); HtmlNode volume24 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "5"); HtmlNode marketCap = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "7"); try { WalletInvestorDataItem item = new WalletInvestorDataItem(); item.Name = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); item.LastPrice = Convert.ToDouble(CorrectString(prices.Element("a").InnerText)); item.Rise = change24.Element("a").GetAttributeValue("class", "") != "red"; string change = CorrectString(change24.InnerText); item.Change24 = Convert.ToDouble(change); if (item.Change24 < percent) { finished = true; break; } item.Volume = volume24.InnerText.Trim(); item.MarketCap = marketCap.Element("a").InnerText.Trim(); item.ListedOnBinance = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name) != null; item.ListedOnBittrex = BittrexExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name) != null; item.ListedOnBitmex = BitmexExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == item.Name) != null; if (!item.ListedOnBinance && !item.ListedOnBitmex && !item.ListedOnBittrex) { continue; } list.Add(item); } catch (Exception) { continue; } } if (finished) { break; } } Log(LogType.Success, "pull items data from walletinvestor.com", 0, 0, StrategyOperation.Connect); Log(LogType.Warning, string.Format("found {0} items matched min 24h% and exchanges", list.Count), 0, 0, StrategyOperation.Connect); Log(LogType.Log, "initialize forecast data provider", 0, 0, StrategyOperation.Connect); if (!ForecastProvider.Initialize(this)) { Log(Crypto.Core.Common.LogType.Error, "Cannot initialize forecast provider.", 0, 0, StrategyOperation.Connect); return; } Log(LogType.Success, "initialize forecast data provider", 0, 0, StrategyOperation.Connect); Log(LogType.Log, "get forecast data", 0, 0, StrategyOperation.Connect); List <WalletInvestorDataItem> filtered = new List <WalletInvestorDataItem>(); for (int i = 0; i < list.Count; i++) { var item = list[i]; ForecastProvider.UpdateForecast(this, item); if (item.Forecast7Day >= Day7MinPercent && item.Forecast14Day >= Day14MinPercent && item.Forecast3Month >= Month3MinPercent) { filtered.Add(item); } } for (int fi = 0; fi < filtered.Count; fi++) { var item = filtered[fi]; if (Items.FirstOrDefault(i => i.Name == item.Name) != null) { continue; } Items.Add(item); Log(item); } if (Items.Count == 0) { Log(LogType.Warning, "no items found matched criteria", 0, 0, StrategyOperation.Connect); } Log(LogType.Success, "get forecast data", 0, 0, StrategyOperation.Connect); ForecastProvider.Clear(); LastCheckTime = DateTime.Now; }