public static async Task <List <CoinStats> > GetCoinStats() { string queryString = "http://miningpoolhub.com/index.php?page=api&action=getminingandprofitsstatistics"; List <CoinStats> coins = new List <CoinStats>(); dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false); if (results["return"] != null) { var returnData = results["return"]; foreach (var c in returnData) { CoinStats coin = new CoinStats(); coin.coinName = c["coin_name"]; coin.host = c["host"]; coin.hostList = c["host_list"]; coin.port = (long)c["port"]; coin.directMiningHost = c["direct_mining_host"]; coin.directMiningHostList = c["direct_mining_host_list"]; coin.directMiningPort = (long)c["direct_mining_algo_port"]; coin.algorithm = c["algo"]; coin.normalizedProfit = (double)c["normalized_profit"]; coin.normalizedProfitAmd = (double)c["normalized_profit_amd"]; coin.normalizedProfitNvidia = (double)c["normalized_profit_nvidia"]; coin.profit = (double)c["profit"]; coin.poolHash = c["pool_hash"]; coin.netHash = c["net_hash"]; coin.difficulty = (double)c["difficulty"]; coin.reward = (double)c["reward"]; coin.lastBlock = (long)c["last_block"]; coin.timeSinceLastBlock = (long)c["time_since_last_block"]; coin.timeSinceLastBlockInWords = c["time_since_last_block_in_words"]; coin.bittrexBuyPrice = c["bittrex_buy_price"]; coin.cryptsyBuyPrice = c["cryptsy_buy_price"]; coin.yobitBuyPrice = c["yobit_buy_price"]; coin.poloniexBuyPrice = c["poloniex_buy_price"]; coin.highestBuyPrice = c["highest_buy_price"]; coins.Add(coin); } return(coins); } else { return(null); } }
private static void DoWork() { Process process = null; int loops = 0; while (true) { loops++; bool fetched = false; while (fetched == false) { try { FetchData(); fetched = true; } catch { System.Console.Error.WriteLine("Polling multipoolhub failed, trying again..."); System.Threading.Thread.Sleep(5000); } } if (topCoin.coinName == coins[0].coinName) { if (loops % 5 == 0) { System.Console.WriteLine("{0} is still the most profitable coin.", topCoin.coinName); } } else { try { if (process != null) { System.Console.WriteLine("{0} is not the most profitable coin.", topCoin.coinName);//, with a normalised profit rating of {1}", topCoin.coinName, topCoin.normalizedProfitNvidia); process.Kill(); } } catch { System.Console.Error.WriteLine("Failed to terminate process"); } try { CoinStats coin = coins[0]; Miner miner = config.miners.Find(x => x.algorithm == coin.algorithm); miner.arguments = string.Format(miner.arguments, coin.host, coin.port, config.user, config.rig); process = new Process { StartInfo = new ProcessStartInfo { FileName = miner.filename, Arguments = miner.arguments, RedirectStandardOutput = false, UseShellExecute = false, CreateNoWindow = true, } }; process.Start(); } catch { System.Console.Error.WriteLine("Failed to start process"); } } try { topCoin = coins[0]; if (process.HasExited) { System.Console.WriteLine("{0} miner appears to have exited, attempting to restart", topCoin.coinName, topCoin.normalizedProfitNvidia); process.Start(); } else { System.Console.WriteLine("Mining {0}, with a normalised profit rating of {1}", topCoin.coinName, topCoin.normalizedProfitNvidia); } } catch { } System.Threading.Thread.Sleep(60000); } }