Example #1
0
        public decimal GetTransactionsFee(ICurrencyIdentity aCurrency)
        {
            decimal?lResult = null;

            if (FLastFeesDataRetrieval == DateTime.MinValue || FLastFeesDataRetrieval < DateTime.UtcNow.AddDays(-1))
            {
                using (var lClient = new BitfinexClient())
                {
                    var lResponse = lClient.GetWithdrawalFeesAsync().Result;
                    if (!lResponse.Success)
                    {
                        throw new Exception($"Failed to get withdrawn fees from exchange server. {lResponse.Error}");
                    }
                    var lFees = lResponse.Data.Withdraw;
                    FWithdrawnFeesCache.Clear();
                    foreach (var lFee in lFees)
                    {
                        FWithdrawnFeesCache.TryAdd(lFee.Key, lFee.Value);
                    }
                }
                FLastFeesDataRetrieval = DateTime.UtcNow;
            }

            if (FWithdrawnFeesCache.TryGetValue(aCurrency.Ticker, out decimal lTxFee))
            {
                lResult = lTxFee;
            }
            else
            {
                using (var lClient = new BitfinexClient())
                {
                    var lResponse = lClient.GetCurrenciesAsync().Result;
                    if (lResponse.Success)
                    {
                        var lExchangeTicker = lResponse.Data.Where(lCurrency => string.Equals(lCurrency.FullName, aCurrency.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.Name;
                        if (lExchangeTicker != null && FWithdrawnFeesCache.TryGetValue(lExchangeTicker, out lTxFee))
                        {
                            lResult = lTxFee;
                        }
                    }
                }
            }

            return(lResult ?? throw new Exception($"Transaction fee for currency with ticker '{aCurrency.Ticker}' not found"));
        }