public static void UpdateAPI(string worker) { string resp = NiceHashStats.GetNiceHashAPIData(apiUrl, worker); if (resp != null) { try { var LastResponse = JsonConvert.DeserializeObject <ExchangeRateJSON>(resp, Globals.JsonSettings); // set that we have a response if (LastResponse != null) { Result last_result = LastResponse.result; ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency; exchanges_fiat = last_result.exchanges_fiat; // ActiveDisplayCurrency = "USD"; // check if currency avaliable and fill currency list foreach (var pair in last_result.exchanges) { if (pair.ContainsKey("USD") && pair.ContainsKey("coin") && pair["coin"] == "BTC" && pair["USD"] != null) { USD_BTC_rate = Helpers.ParseDouble(pair["USD"]); break; } } } } catch (Exception e) { Helpers.ConsolePrint("ExchangeRateAPI", "UpdateAPI got Exception: " + e.Message); } } else { Helpers.ConsolePrint("ExchangeRateAPI", "UpdateAPI got NULL"); } }
public static bool GetCurrentBlock(string worker) { string ret = NiceHashStats.GetNiceHashAPIData("https://etherchain.org/api/blocks/count", worker); if (ret == null) { return(false); } ret = ret.Substring(ret.LastIndexOf("count") + 7); CurrentBlockNum = ret.Substring(0, ret.Length - 3); return(true); }
public static void GetCurrentBlock(string worker) { string ret = NiceHashStats.GetNiceHashAPIData("https://etherchain.org/api/blocks/count", worker); if (ret == null) { Helpers.ConsolePrint(worker, String.Format("Failed to obtain current block, using default {0}.", ConfigManager.GeneralConfig.ethminerDefaultBlockHeight)); CurrentBlockNum = ConfigManager.GeneralConfig.ethminerDefaultBlockHeight.ToString(); } else { ret = ret.Substring(ret.LastIndexOf("count") + 7); CurrentBlockNum = ret.Substring(0, ret.Length - 3); } }
public APIData GetSummary() { string resp; string aname = null; APIData ad = new APIData(); if (AlgoNameIs("ethereum")) { try { resp = NiceHashStats.GetNiceHashAPIData("http://127.0.0.1:" + Config.ConfigData.APIBindPortEthereumFrontEnd + "/stats", MinerDeviceName); if (resp == null) { return(null); } if (resp.Length < 800) { return(null); // response is too short } Eth <EthMiner> oo; oo = JsonConvert.DeserializeObject <Eth <EthMiner> >(resp); ad.Speed = 0; aname = "ethereum"; for (int i = 0; i < oo.miners.Length; i++) { if (!oo.miners[i].name.Equals(MinerDeviceName)) { continue; } if (oo.miners[i].timeout == true) { Helpers.ConsolePrint(MinerDeviceName, "Ethminer ERROR!"); return(null); } else if (oo.miners[i].warning == true) { Helpers.ConsolePrint(MinerDeviceName, "Ethminer WARNING!"); } ad.Speed = oo.miners[i].hashrate * 1000; break; } if (ad.Speed == 0) { return(null); } } catch (Exception e) { Helpers.ConsolePrint(MinerDeviceName, "GetSummary: " + e.Message); return(null); } } else { resp = GetAPIData(APIPort, "summary"); if (resp == null) { return(null); } try { string[] resps; if (!MinerDeviceName.Equals("AMD_OpenCL")) { resps = resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < resps.Length; i++) { string[] optval = resps[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optval.Length != 2) { continue; } if (optval[0] == "ALGO") { aname = optval[1]; } else if (optval[0] == "KHS") { ad.Speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS } } } else { // Checks if all the GPUs are Alive first string resp2 = GetAPIData(APIPort, "devs"); if (resp2 == null) { return(null); } string[] checkGPUStatus = resp2.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < checkGPUStatus.Length - 1; i++) { if (!checkGPUStatus[i].Contains("Status=Alive")) { Helpers.ConsolePrint(MinerDeviceName, "GPU " + i + ": Sick/Dead/NoStart/Initialising/Disabled/Rejecting/Unknown"); return(null); } } resps = resp.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (resps[1].Contains("SUMMARY")) { string[] data = resps[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Get miner's current total speed string[] speed = data[4].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); // Get miner's current total MH double total_mh = Double.Parse(data[18].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1], new CultureInfo("en-US")); ad.Speed = Double.Parse(speed[1]) * 1000; aname = SupportedAlgorithms[CurrentAlgo].MinerName; if (total_mh <= PreviousTotalMH) { Helpers.ConsolePrint(MinerDeviceName, "SGMiner might be stuck as no new hashes are being produced"); Helpers.ConsolePrint(MinerDeviceName, "Prev Total MH: " + PreviousTotalMH + " .. Current Total MH: " + total_mh); return(null); } PreviousTotalMH = total_mh; } else { ad.Speed = 0; } } } catch { return(null); } } FillAlgorithm(aname, ref ad); return(ad); }