private async Task <IReadOnlyList <BalanceRecord> > GetInUsdAsync(ICollection <BalanceRecord> balanceRecords)
        {
            var balanceRecordsInUsd = (await _rateCalculatorClient.GetAmountInBaseAsync(balanceRecords, Usd)).ToList();

            if (balanceRecords.Count != balanceRecordsInUsd.Count)
            {
                throw new InvalidOperationException("Wrong number of USD balances is returned. " +
                                                    $"Balance records in request: {balanceRecords.Count}, " +
                                                    $"balance records in response: {balanceRecordsInUsd.Count}");
            }

            return(balanceRecordsInUsd);
        }
        public async Task <(double convertedAmount, string assetId)> ConvertAsync(string assetFrom, double amount)
        {
            var defaultAsset = _settingsService.GetDefaultAsset();

            if (assetFrom == defaultAsset)
            {
                return(amount, defaultAsset);
            }

            var convertedAmount = await _rateCalculatorClient.GetAmountInBaseAsync(assetFrom, amount, defaultAsset);

            if (amount != 0 && convertedAmount == 0)
            {
                _log.Warning($"Conversion from {amount} {assetFrom} to {defaultAsset} resulted in 0.");
            }

            return(convertedAmount, defaultAsset);
        }
예제 #3
0
        public async Task <(string assetTo, double convertedAmount)> ConvertAsync(
            string assetFrom,
            string assetTo,
            double amount,
            bool forceConvesion = false)
        {
            if (assetFrom == assetTo || IsNotConvertible(assetFrom) && !forceConvesion)
            {
                return(assetFrom, amount);
            }

            double convertedAmount = await _rateCalculatorClient.GetAmountInBaseAsync(assetFrom, amount, assetTo);

            if (amount != 0 && convertedAmount == 0)
            {
                _log.Warning(
                    nameof(ConvertAsync),
                    $"Conversion from {amount} {assetFrom} to {assetTo} resulted in 0.");
            }

            return(assetTo, convertedAmount);
        }
예제 #4
0
 private async Task <double> GetAmountInOperationAssetAsync(string tierAssetId, string assetId, double amount)
 {
     return(tierAssetId == assetId
         ? amount
         : await _rateCalculatorClient.GetAmountInBaseAsync(tierAssetId, amount, assetId));
 }
예제 #5
0
 private async Task <double> GetAmountAsync(string assetId, double amount, string baseAssetId)
 {
     return(assetId == baseAssetId
         ? amount
         : await _rateCalculatorClient.GetAmountInBaseAsync(assetId, amount, baseAssetId));
 }