예제 #1
0
        private async Task <IReadOnlyList <AssetPair> > GetAllAssetPairsFromCacheAsync()
        {
            var assetsTask     = GetAllAssetsAsync();
            var assetPairsTask = _cache.GetOrAddAsync("AssetPairs", async() => await _client.GetAllAssetPairsAsync(), _cacheDuration);

            await Task.WhenAll(assetsTask, assetPairsTask);

            var assetPairs = assetPairsTask.Result.ToList();
            var assets     = assetsTask.Result;

            foreach (var assetPair in assetPairs)
            {
                var baseAsset  = assets.FirstOrDefault(x => x.AssetId == assetPair.BaseAssetId);
                var quoteAsset = assets.FirstOrDefault(x => x.AssetId == assetPair.QuoteAssetId);

                assetPair.BaseAssetAccuracy  = baseAsset?.Accuracy ?? 0;
                assetPair.QuoteAssetAccuracy = quoteAsset?.Accuracy ?? 0;
            }

            return(assetPairs);
        }
예제 #2
0
        private async Task<IReadOnlyList<AssetPair>> GetAllAssetPairsFromCacheAsync()
        {
            var assetsTask = GetAllAssetsAsync();
            var assetPairsTask = _cache.GetOrAddAsync("AssetPairs", async () => await _client.GetAllAssetPairsAsync(), _cacheDuration);

            await Task.WhenAll(assetsTask, assetPairsTask);

            var assetPairs = assetPairsTask.Result.ToList();
            var assets = assetsTask.Result;

            var result = new List<AssetPair>();

            foreach (var assetPair in assetPairs)
            {
                var baseAsset = assets.FirstOrDefault(x => x.AssetId == assetPair.BaseAssetId);
                var quoteAsset = assets.FirstOrDefault(x => x.AssetId == assetPair.QuoteAssetId);
                if (baseAsset == null || quoteAsset == null)
                    continue;

                assetPair.BaseAssetAccuracy = baseAsset.Accuracy;
                assetPair.QuoteAssetAccuracy = quoteAsset.Accuracy;
                result.Add(assetPair);
            }

            return result;
        }