private CoinInfo GetCoinInfoFromCryptoCompare(CoinFamily coinType) { var url = "https://min-api.cryptocompare.com/data/price?fsym=" + coinType.ToString().ToUpper() + "&tsyms=BTC,USD"; var json = new WebClient().DownloadString(url); var response = JsonConvert.DeserializeObject <CryptoCompareResponse>(json); return(new CoinInfo { CoinType = coinType.ToString(), Name = coinType.ToString(), CoinMarketCapId = 0, PriceUSD = response.USD, PriceBTC = response.BTC, Updated = DateTime.Now }); }
private static CoinFamily HandleFamilyOverride(CoinFamily family, PoolConfig pool) { switch (family) { case CoinFamily.Equihash: var equihashTemplate = pool.Template.As <EquihashCoinTemplate>(); if (equihashTemplate.UseBitcoinPayoutHandler) { return(CoinFamily.Bitcoin); } break; } return(family); }
public async Task <CoinInfoResponse> GetCoinInfo(string coin) { var coinType = (CoinFamily)CoinFamily.Parse(typeof(CoinFamily), coin, true); var coinInfo = await cf.Run(con => coinInfoRepo.GetCoinInfo(con, coinType.ToString())); if (coinInfo == null || DateTime.Now.Subtract(coinInfo.Updated).TotalMinutes > 5) { coinInfo = GetCoinInfoFromCryptoCompare(coinType); await cf.RunTx((con, tx) => coinInfoRepo.AddCoinInfo(con, tx, coinInfo)); } var response = new CoinInfoResponse { CoinType = coinInfo.CoinType.ToString(), Name = coinInfo.Name, PriceBTC = coinInfo.PriceBTC, PriceUSD = coinInfo.PriceUSD }; return(response); }