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 virtual void DownloadCoinPredictorForecast() { this.siStatus.Caption = "<b>Connecting Binance</b>"; Application.DoEvents(); BinanceExchange.Default.Connect(); Stop = false; var handle = SplashScreenManager.ShowOverlayForm(this.gridControl); double percent = Settings.Min24HourChange; string adress = "https://coinpredictor.io/ranks?t=price&from=0&to=3000&sort=day&d=desc&type=number"; this.siStatus.Caption = "<b>Downloading data from coinpredictor.io</b>"; Application.DoEvents(); WebClient wc = new WebClient(); string text = wc.DownloadString(adress); if (string.IsNullOrEmpty(text)) { SplashScreenManager.CloseOverlayForm(handle); XtraMessageBox.Show("Error downloading data from coinpredictor.io. Please contact developer"); this.siStatus.Caption = "<b>Error downloading data from coinpredictor.io</b>"; SplashScreenManager.CloseOverlayForm(handle); return; } JObject obj = (JObject)JsonConvert.DeserializeObject(text); if (obj == null) { SplashScreenManager.CloseOverlayForm(handle); XtraMessageBox.Show("Error deserializing data from coinpredictor.io. Please contact developer"); this.siStatus.Caption = "<b>Error deserializing data from coinpredictor.io</b>"; SplashScreenManager.CloseOverlayForm(handle); return; } JArray list = obj.Value <JArray>("list"); if (list == null) { SplashScreenManager.CloseOverlayForm(handle); XtraMessageBox.Show("Error deserializing data from coinpredictor.io. Please contact developer"); this.siStatus.Caption = "<b>Error deserializing data from coinpredictor.io</b>"; SplashScreenManager.CloseOverlayForm(handle); return; } this.siStatus.Caption = string.Format("<b>Parsing data (total {0})</b>", list.Count); Application.DoEvents(); this.beProgress.EditValue = 0; this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; int index = 0; List <CoinPredictorDataItem> cplist = new List <CoinPredictorDataItem>(); CpItems = cplist; for (int i = 0; i < list.Count; i++) { JObject item = (JObject)list[i]; if (Stop) { break; } string name = item.Value <string>("ticker"); Ticker ticker = BinanceExchange.Default.Tickers.FirstOrDefault(t => t.MarketCurrency == name && t.BaseCurrency == "BTC"); if (ticker == null) { continue; } string slug = item.Value <string>("slug"); string description = item.Value <string>("name"); CoinPredictorDataItem cp = new CoinPredictorDataItem(); cp.Name = name; cp.Description = description; cp.BinanceLink = ticker.WebPageAddress; cp.ForecastLink = string.Format("https://coinpredictor.io/{0}#price", slug.ToLower()); double day7 = GetDoubleProperty(item, "dayFormatted", 0); double day1 = GetDoubleProperty(item, "dayFormattedFirst", 0); double week4 = GetDoubleProperty(item, "weekFormatted", 0); double month = GetDoubleProperty(item, "monthFormatted", 0); double price = GetDoubleProperty(item, "priceFormatted", 0); cp.LastPrice = price; cp.Forecast1Day = day1; cp.Forecast7Day = day7; cp.Forecast4Week = week4; cp.Forecast3Month = month; cp.ListedOnBinance = BinanceExchange.Default.GetTicker(cp.Name) != null; cp.Match = cp.Forecast1Day >= Settings.MinCp24HourChange && cp.Forecast7Day >= Settings.MinCp7DayChange && cp.Forecast4Week >= Settings.MinCp4WeekChange && cp.Forecast3Month >= Settings.MinCp3MonthChange; cplist.Add(cp); int progress = index * 100 / list.Count; if (((int)this.beProgress.EditValue) != progress) { this.beProgress.EditValue = progress; this.gridView2.RefreshData(); Application.DoEvents(); } index++; } this.beProgress.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; this.siStatus.Caption = Stop? "<b>Interrupted</b>": "<b>Done</b>"; this.gridView2.RefreshData(); SplashScreenManager.CloseOverlayForm(handle); UpdateCombined(); XtraMessageBox.Show(string.Format("Found {0} items matched criteria", CpItems.Count(i => i.Match))); }