コード例 #1
0
ファイル: RatesService.cs プロジェクト: LykkeCity/LykkePayAPI
        public async Task <AssetPairRate> Get(string assetPairId)
        {
            var response = await _marketProfileService.ApiMarketProfileByPairCodeGetAsync(assetPairId);

            if (response is ErrorModel error)
            {
                throw new ApiRequestException(error.Message, error.Code?.ToString());
            }

            if (response is AssetPairModel assetPairRate)
            {
                IReadOnlyDictionary <string, AssetPair> assetPairs = await _assetPairsCache.GetDictionaryAsync();

                var assetPair = assetPairs.ContainsKey(assetPairId) ? assetPairs[assetPairId] : null;

                if (assetPair == null)
                {
                    throw new Exception($"Asset pair {assetPairId} doesn't exist");
                }

                return(new AssetPairRate
                {
                    AssetPairId = assetPair.Id,
                    Ask = (decimal)assetPairRate.AskPrice,
                    Bid = (decimal)assetPairRate.BidPrice,
                    Accuracy = assetPair.Accuracy
                });
            }

            throw new Exception("Unknown MarketProfile API response");
        }
コード例 #2
0
        private async Task <AssetPairModel> InvokeMarketProfileServiceAsync(string assetPairId)
        {
            object response = await _marketProfileServiceClient.ApiMarketProfileByPairCodeGetAsync(assetPairId);

            if (response is ErrorModel error)
            {
                throw new Exception(error.Message);
            }

            if (response is AssetPairModel assetPairRate)
            {
                return(assetPairRate);
            }

            throw new UnrecognizedApiResponse("Unknown MarketProfile API response");
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pairCode'>
 /// </param>
 public static object ApiMarketProfileByPairCodeGet(this ILykkeMarketProfile operations, string pairCode)
 {
     return(operations.ApiMarketProfileByPairCodeGetAsync(pairCode).GetAwaiter().GetResult());
 }