public IEnumerable <InterestsPerCoin> GetInterestsForSpecificTimeframe(string apiKey, DateTime from, DateTime to, string fiatCurrencyToCalcValue)
        {
            IEnumerable <CelsiusTransactionModel> transactionsPerYear = GetTransactionsForSpecificTimeframe(apiKey, from, to)
                                                                        .Where(t => t.nature == CelsiusTransactionNatureInterests && t.state == CelsiusTransactionStateConfirmed);

            List <InterestsPerCoin> interestsByCoin = new List <InterestsPerCoin>();

            foreach (var interestByCoin in transactionsPerYear.GroupBy(t => t.original_interest_coin))
            {
                interestsByCoin.Add(new InterestsPerCoin()
                {
                    Coin                = interestByCoin.Key,
                    UsdValue            = interestByCoin.Sum(c => c.amount_usd),
                    ValueInSelectedFiat = interestByCoin.Sum(c => _rateService.GetExchangeRateToUsd(fiatCurrencyToCalcValue, c.time.Date) * c.amount_usd)
                });
            }

            return(interestsByCoin.Where(i => i.UsdValue > new decimal(0.01)));
        }
Exemple #2
0
        public WalletModel GetWallet(string apiKey, string fiatCurrencyToDisplayValues)
        {
            WalletModel         model    = new WalletModel();
            List <BalanceModel> balances = new List <BalanceModel>();

            var     response = _celsiusApiService.GetResultFromCelsiusPrivateApi(apiKey, Constants.CelsiusApiGetWalletBalance);
            dynamic des      = JsonConvert.DeserializeObject(response.Content);

            decimal fiatExchangeRateToUsd = 1;

            if (fiatCurrencyToDisplayValues.ToUpper() != UsdFiatCurrencySymbol)
            {
                fiatExchangeRateToUsd = _exchangeService.GetExchangeRateToUsd(fiatCurrencyToDisplayValues);
            }

            foreach (var currency in _currencyService.GetSupportedCurrencies(apiKey))
            {
                string  currentCurrency = currency.ToString();
                decimal amount          = des["balance"][currentCurrency.ToLower()];

                if (amount > 0)
                {
                    var balanceModel = new BalanceModel
                    {
                        Amount                = amount,
                        Currency              = currency,
                        ValueInUsd            = GetValueInUsd(apiKey, currentCurrency),
                        FiatCurrencyToDisplay = fiatCurrencyToDisplayValues
                    };

                    balanceModel.ValueInCurrencyToDisplay = balanceModel.ValueInUsd * fiatExchangeRateToUsd;
                    balances.Add(balanceModel);
                }
            }

            model.Balances          = balances.OrderByDescending(b => b.ValueInUsd);
            model.CurrentCelBalance = balances.SingleOrDefault(b => b.Currency == Constants.CelTicker)?.Amount;
            return(model);
        }