protected override async Task <JobResult> RunInternalAsync(JobContext context) { try { SimplePriceResponse response = await _api.GetSimplePrice(new SimplePriceRequest { Ids = Ids, Currencies = Currencies, IncludeMarketCap = true, Include24HrChange = true, Include24HrVol = true }) .AnyContext(); Price price = await _statsCache.GetAsync(Price.DefaultCacheKey, new Price()).AnyContext(); price.BtcPrice = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Btc); price.BtcMarketCap = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.BtcMarketCap); price.Btc24HrVol = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Btc24HrVol); price.Btc24HrChange = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Btc24HrChange); price.UsdPrice = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Usd); price.UsdMarketCap = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.UsdMarketCap); price.Usd24HrVol = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Usd24HrVol); price.Usd24HrChange = GetCoinPropertyByKey(response, Ellaism.Id, Ellaism.Usd24HrChange); await _statsCache.SetAsync(Price.DefaultCacheKey, price).AnyContext(); } catch (Exception e) { return(JobResult.FromException(e)); } return(JobResult.Success); }
private static decimal GetCoinPropertyByKey(SimplePriceResponse response, string coin, string property) { Dictionary <string, double?> t = response.FirstOrDefault(r => r.Key == coin).Value; double?value = t?.FirstOrDefault(p => p.Key == property).Value; return(value != null ? (decimal)value : 0); }