/// <summary> /// Utility method: GetCoinSnapshotByID - Invoke CryptoCompare.com API's CoinSnapshotFullById call to /// obtain the additional elements (i.e. current blocks, block reward, total coins mined, etc.) that /// are not provided by CryptoCompare.com API's coinlist call, given the numeric id of a coin /// </summary> /// <param name="client"></param> /// <param name="coinInformation"></param> /// <returns>void</returns> private void GetCoinSnapshotByID(ApiWebClient client, CoinInformation coinInformation) { string coinSnapshotIDParam = ""; // Obtain numeric id of the coin whose full record is passed in as coinInformation parameter coinSnapshotIDParam = coinInformation.Id; // Build URL string for the CoinSnapshotFullById CryptoCompare.com API call string apiUrl = BuildApiUrlByID(coinSnapshotIDParam, "CoinSnapshotByID"); // Invoke CryptoCompare.com API's CoinSnapshotFullById call URL, then deserialize result and populate // the additional fields provided by this API call into the coinInformation coin record string json = client.DownloadAsString(apiUrl); try { RootObjectCoinSnapshot coinsnapshotset = JsonConvert.DeserializeObject <RootObjectCoinSnapshot>(json); GeneralCoinSnapshotData coinSnapshot = new GeneralCoinSnapshotData(); coinSnapshot = coinsnapshotset.Data.General; coinInformation.PopulateFromJson(coinSnapshot); } catch (Exception e) { string errorMsg = e.Message; } }
// This overload of PopulateFromJson populates the additional elements of a single CoinInformation object, // as deserialized from CryptoCompare.com API's CoinSnapshotFullById call public static void PopulateFromJson(this CoinInformation coinInformation, GeneralCoinSnapshotData snapshot) { coinInformation.CurrentBlocks = Convert.ToInt32(snapshot.BlockNumber); coinInformation.Reward = Convert.ToDouble(snapshot.BlockReward); coinInformation.TotalCoinsMined = snapshot.TotalCoinsMined; coinInformation.RewardReduction = snapshot.BlockRewardReduction; coinInformation.EstimatedBlockTime = Convert.ToDouble(snapshot.BlockTime); coinInformation.NetworkHashRate = Convert.ToDouble(snapshot.NetHashesPerSecond); }