public async Task <IReadOnlyList <AssetInfo> > GetAllAsync() { var settings = await _settingsService.GetAsync(); var marketCaps = _indexCalculator.GetAllAssetsMarketCaps(); var prices = _tickPricesService.GetAssetPrices(settings.Sources.ToList()); var result = new List <AssetInfo>(); foreach (var asset in settings.Assets) { if (!marketCaps.ContainsKey(asset)) { continue; } var marketCap = marketCaps[asset]; if (!prices.ContainsKey(asset)) { continue; } var allAssetPrices = prices[asset]; var sources = allAssetPrices.Select(x => x.Source).Distinct().ToList(); var assetPrices = new Dictionary <string, decimal>(); foreach (var source in sources) { var assetSourcePrices = allAssetPrices.Where(x => x.Source == source).ToList(); var middlePrice = Utils.GetMiddlePrice(asset, assetSourcePrices); assetPrices.Add(source, middlePrice); } var assetInfo = new AssetInfo { Asset = asset, MarketCap = marketCap, Prices = assetPrices }; result.Add(assetInfo); } return(result); }
public async Task <IReadOnlyList <string> > GetAssetsAsync() { var settings = await _settingsService.GetAsync(); var marketCapsAssets = _indexCalculator.GetAllAssetsMarketCaps().Keys.ToList(); var prices = _tickPricesService.GetAssetPrices(settings.Sources.ToList()); if (marketCapsAssets.Any()) { foreach (var priceAsset in prices.Keys.ToList()) { if (!marketCapsAssets.Contains(priceAsset)) { prices.Remove(priceAsset); } } } var result = prices.Select(x => x.Key) .Distinct() .OrderBy(x => x) .ToList(); return(result); }