// estimate revenue over an interval private void OnChanged() { Profitability p = new Profitability(); try { tbIncome.Text = p.ProfitOnInterval(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value), Convert.ToDecimal(tbHashrate.Text) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value), Convert.ToDecimal(tbReward.Text), Convert.ToDecimal(tbDifficulty.Text)).ToString("F8"); if (tbExchangeRate.Text != "") { tbIncomeBTC.Text = p.ProfitOnIntervalBTC(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value), Convert.ToDecimal(tbHashrate.Text) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value), Convert.ToDecimal(tbReward.Text), Convert.ToDecimal(tbDifficulty.Text), Convert.ToDecimal(tbExchangeRate.Text)).ToString("F8"); } else { tbIncomeBTC.Text = "---"; } } catch { tbIncome.Text = tbIncomeBTC.Text = "---"; } }
static int Lookup(string szSelectedCoin, decimal hashrate, bool bIncomeInBTC, long interval, string exchange, RegistrySettings rs) { Profitability p = new Profitability(); CoinInformation ci = new CoinInformation(); ExchangeInformation ei = new ExchangeInformation(); CoinInfo inf = rs.Coins[szSelectedCoin]; double diff = 0; try { diff = ci.GetDifficulty(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); } catch { Console.WriteLine("Unable to fetch difficulty"); return(-1); } decimal reward = 0; try { reward = ci.GetReward(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); } catch { Console.WriteLine("Unable to fetch reward"); return(-1); } if (hashrate == 0) { switch (inf.DefaultHashRateUnit) { case "H/s": hashrate = Convert.ToDecimal(inf.DefaultHashRate); break; case "kH/s": hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000; break; case "MH/s": hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000000; break; case "GH/s": hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 100000000; break; default: throw new ArgumentException("invalid hashrate unit"); } } if (!bIncomeInBTC) { Console.WriteLine(p.ProfitOnInterval(interval, hashrate, reward, (decimal)diff).ToString("F8")); } else { decimal exchrate = 0; try { exchrate = (szSelectedCoin.ToLower() != "bitcoin") ? ei.GetExchangeRate((exchange != "") ? exchange : inf.Exchange, inf.Abbreviation) : 1; } catch { Console.WriteLine("Unable to fetch exchange rate"); return(-1); } Console.WriteLine(p.ProfitOnIntervalBTC(interval, hashrate, reward, (decimal)diff, exchrate).ToString("F8")); } return(0); }