public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "") { ApiWebClient client = new ApiWebClient(); if (!string.IsNullOrEmpty(userAgent)) client.Headers.Add("user-agent", userAgent); //get GPU coin info (scrypt, X11, etc) string jsonString = client.DownloadString(GetApiUrl()); Data.ApiResponse apiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString); //merge in ASIC coin info (sha-256, scrypt, etc) jsonString = client.DownloadString(GetAsicApiUrl()); Data.ApiResponse asicApiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString); foreach (string coinName in asicApiResponse.Coins.Keys) apiResponse.Coins[coinName] = asicApiResponse.Coins[coinName]; List<CoinInformation> result = new List<CoinInformation>(); foreach (string coinName in apiResponse.Coins.Keys) { CoinInformation coinInformation = new CoinInformation(); coinInformation.Name = coinName; coinInformation.PopulateFromJson(apiResponse.Coins[coinName]); if (coinInformation.Difficulty > 0) //only add coins with valid info since the user may be basing //strategies on Difficulty result.Add(coinInformation); } return result; }
public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "") { WebClient client = new ApiWebClient(); if (!string.IsNullOrEmpty(userAgent)) client.Headers.Add("user-agent", userAgent); string apiUrl = GetApiUrl(); string jsonString = client.DownloadString(apiUrl); JObject jsonObject = JObject.Parse(jsonString); if (!jsonObject.Value<bool>("Success")) { throw new CoinApiException(jsonObject.Value<string>("Message")); } JArray jsonArray = jsonObject.Value<JArray>("Data"); List<CoinInformation> result = new List<CoinInformation>(); foreach (JToken jToken in jsonArray) { CoinInformation coinInformation = new CoinInformation(); coinInformation.PopulateFromJson(jToken); if (coinInformation.Difficulty > 0) //only add coins with valid info since the user may be basing //strategies on Difficulty result.Add(coinInformation); } return result; }
public IEnumerable<MultipoolInformation> GetMultipoolInformation(string userAgent = "") { WebClient client = new ApiWebClient(); if (!string.IsNullOrEmpty(userAgent)) client.Headers.Add("user-agent", userAgent); string apiUrl = GetApiUrl(); string jsonString = client.DownloadString(apiUrl); JObject jsonObject = JObject.Parse(jsonString); jsonObject = jsonObject.Value<JObject>("result"); JArray jsonArray = jsonObject.Value<JArray>("stats"); List<MultipoolInformation> result = new List<MultipoolInformation>(); foreach (JToken jToken in jsonArray) { MultipoolInformation multipoolInformation = new MultipoolInformation(); if (multipoolInformation.PopulateFromJson(jToken)) result.Add(multipoolInformation); } MultipoolInformation btcInformation = result.Single(mpi => mpi.Algorithm.Equals(AlgorithmNames.SHA256)); foreach (MultipoolInformation otherInformation in result) { KnownAlgorithm knownAlgorithm = KnownAlgorithms.Algorithms.Single(ka => ka.Name.Equals(otherInformation.Algorithm)); otherInformation.Profitability = ((otherInformation.Price * knownAlgorithm.Multiplier) / btcInformation.Price) * PoolProfitability * 100; } return result; }
public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "") { WebClient client = new ApiWebClient(); if (!string.IsNullOrEmpty(userAgent)) client.Headers.Add("user-agent", userAgent); string apiUrl = GetApiUrl(); string jsonString = client.DownloadString(apiUrl); JObject jsonObject = JObject.Parse(jsonString); string resultStatus = jsonObject.Value<string>("status"); if (!resultStatus.Equals("success", StringComparison.OrdinalIgnoreCase)) throw new CoinApiException(resultStatus); List<CoinInformation> result = new List<CoinInformation>(); JArray jsonArray = jsonObject.Value<JArray>("Data"); foreach (JToken jToken in jsonArray) { CoinInformation coinInformation = new CoinInformation(); coinInformation.PopulateFromJson(jToken); if (coinInformation.Difficulty > 0) //only add coins with valid info since the user may be basing //strategies on Difficulty result.Add(coinInformation); } CalculateProfitability(result); return result; }
public static Data.SellPrices GetSellPrices() { WebClient webClient = new ApiWebClient(); string response = webClient.DownloadString(new Uri(GetApiUrl())); Data.SellPrices sellPrices = JsonConvert.DeserializeObject<Data.SellPrices>(response); return sellPrices; }
public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "") { WebClient client = new ApiWebClient(); if (!string.IsNullOrEmpty(userAgent)) client.Headers.Add("user-agent", userAgent); string apiUrl = GetApiUrl(); string jsonString = String.Empty; try { jsonString = client.DownloadString(apiUrl); } catch (WebException ex) { if ((ex.Status == WebExceptionStatus.ProtocolError) && (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadGateway)) { //try again 1 more time if error 502 Thread.Sleep(750); jsonString = client.DownloadString(apiUrl); } else throw; } JArray jsonArray = JArray.Parse(jsonString); List<CoinInformation> result = new List<CoinInformation>(); foreach (JToken jToken in jsonArray) { CoinInformation coinInformation = new CoinInformation(); coinInformation.PopulateFromJson(jToken); if (coinInformation.Difficulty > 0) //only add coins with valid info since the user may be basing //strategies on Difficulty result.Add(coinInformation); } return result; }
public static List<AvailableMiner> GetAvailableMiners(string userAgent) { WebClient webClient = new ApiWebClient(); webClient.Headers.Add("user-agent", userAgent); string platform = "win32"; if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX) platform = "osx64"; //include www. to avoid redirect string url = "http://www.multiminerapp.com/miners?platform=" + platform; string response = webClient.DownloadString(new Uri(url)); List<AvailableMiner> availableMiners = JsonConvert.DeserializeObject<List<AvailableMiner>>(response); return availableMiners; }
public static List<Data.RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, string machineName) { if (!url.EndsWith("/")) url = url + "/"; string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&apiKey={4}", url, emailAddress, applicationKey, machineName, apiKey); using (WebClient client = new ApiWebClient()) { string response = ExecuteWebAction(() => { return client.DownloadString(fullUrl); }); JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Deserialize<List<Data.RemoteCommand>>(response); } }