Esempio n. 1
0
        public CoinInfo GetCoinInfo(string coin)
        {
            CoinInfo coinInfo = null;

            using (HttpClient httpClient = new HttpClient())
            {
                var request  = $"https://api.minerstat.com/v2/coins?list={coin}";
                var response = httpClient.GetStringAsync(new Uri(request)).Result;
                coinInfo = JsonConvert.DeserializeObject <List <CoinInfo> >(response).FirstOrDefault();
            }

            return(coinInfo);
        }
Esempio n. 2
0
        public CoinInfo GetCoinHistory(string coin = "ETH", string algo = "Ethash")
        {
            CoinInfo coinInfo = null;

            using (HttpClient httpClient = new HttpClient())
            {
                var  request              = $"https://api.minerstat.com/v2/coins-history?coin={coin}&algo={algo}";
                var  response             = httpClient.GetStringAsync(new Uri(request)).Result;
                var  coinsHistoryResponse = JObject.Parse(response);
                long oneDay = DateTime.UtcNow.AddDays(-1).ToUnixTimeSeconds();
                var  items  = coinsHistoryResponse[coin].Children().Where(c => Convert.ToInt64(((JProperty)c).Name) >= oneDay).Children();
                var  result = items.Average(c => (decimal)c[0]);

                coinInfo = new CoinInfo()
                {
                    coin             = coin,
                    algorithm        = algo,
                    network_hashrate = (long)items.Average(c => (decimal)c[1]),
                    reward           = (float)items.Average(c => Convert.ToDouble(c[2]))
                };
            }

            return(coinInfo);
        }