Пример #1
0
        public async Task <IActionResult> GetAssetPairRates()
        {
            var allAssetPairs = await _assetsHelper.GetAllAssetPairsAsync();

            var allNondisabledAssetPairs = allAssetPairs.Where(x => !x.IsDisabled);

            var allAssets = await _assetsHelper.GetAllAssetsAsync();

            var allTradableNondisabledAssets =
                new HashSet <string>(
                    allAssets
                    .Where(x => !x.IsDisabled && x.IsTradable)
                    .Select(x => x.Id));

            var assetPairsDict = allNondisabledAssetPairs.Where(x =>
                                                                allTradableNondisabledAssets.Contains(x.BaseAssetId) &&
                                                                allTradableNondisabledAssets.Contains(x.QuotingAssetId))
                                 .ToDictionary(x => x.Id);

            var marketProfile = await _marketProfileService.ApiMarketProfileGetAsync();

            var relevantMarketProfile = marketProfile.Where(itm => assetPairsDict.ContainsKey(itm.AssetPair));

            return(Ok(AssetPairRatesResponseModel.Create(
                          relevantMarketProfile.Select(x => x.ToApiModel()).OrderBy(x => x.AssetPair).ToArray())));
        }
        public async Task <IActionResult> GetAssetPairRates()
        {
            var assetPairs = await _assetsService.AssetPairGetAllAsync();

            //var assetPairs = await _assetsService.GetAssetsPairsForClient(new Lykke.Service.Assets.Client.Models.GetAssetPairsForClientRequestModel
            //{
            //    ClientId = _requestContext.ClientId,
            //    IsIosDevice = _requestContext.IsIosDevice,
            //    PartnerId = _requestContext.PartnerId
            //});

            var assetPairsDict = assetPairs.ToDictionary(itm => itm.Id);
            var marketProfile  = await _marketProfileService.ApiMarketProfileGetAsync();

            marketProfile = marketProfile.Where(itm => assetPairsDict.ContainsKey(itm.AssetPair)).ToList();
            return(Ok(AssetPairRatesResponseModel.Create(marketProfile.Select(m => m.ConvertToApiModel()).ToArray())));
        }
Пример #3
0
        /// <summary>
        /// Gets (a set of) market profile(s).
        /// </summary>
        /// <param name="assetPairId">The target asset pair ID. If not specified (is null or empty string), there will be gathered the info about all the registered asset pairs.</param>
        private async Task <List <AssetPairModel> > GetMarketProfilesAsync(string assetPairId = null)
        {
            var marketProfiles = new List <AssetPairModel>();

            if (!string.IsNullOrWhiteSpace(assetPairId))
            {
                var marketProfile = await _marketProfileService.TryGetAssetPairAsync(assetPairId);

                if (marketProfile == null)
                {
                    throw new InvalidOperationException($"Asset pair {assetPairId} is is not registered.");
                }

                marketProfiles.Add(await _marketProfileService.GetAssetPairAsync(assetPairId));
            }
            else
            {
                marketProfiles.AddRange(await _marketProfileService.ApiMarketProfileGetAsync());
            }

            return(marketProfiles);
        }