public double GetBalance(string currency)
 {
     try {
         if (Exchange.GetBalance(this, currency))
         {
             BalanceBase res = Balances.FirstOrDefault(b => b.Currency == currency);
             return(res == null? 0: res.Available);
         }
         return(-1);
     }
     catch (Exception e) {
         Telemetry.Default.TrackException(e);
         return(-1);
     }
 }
예제 #2
0
        public async Task RefreshBalances(Storage.WalletType originalCurrency, CancellationToken cancellationToken)
        {
            var originalBalanceModel = Balances.FirstOrDefault(b => b.WalletType == originalCurrency);

            if (originalBalanceModel == null)
            {
                throw new ArgumentException($"Balance item model for '{originalCurrency}' not found");
            }

            BalanceConverter converter = new BalanceConverter();

            foreach (var balanceItemModel in Balances)
            {
                if (balanceItemModel.WalletType != originalCurrency)
                {
                    var balance = await converter.GetBalance(originalCurrency, originalBalanceModel.Value,
                                                             balanceItemModel.WalletType, cancellationToken);

                    balanceItemModel.Value = balance;
                }
            }
        }