/// <summary> /// Get the Fee Instance from the database /// </summary> /// <param name="baseCurrency"></param> /// <param name="quoteCurrency"></param> /// <param name="amount"></param> /// <returns></returns> private decimal GetFeeInstance(Currency baseCurrency, Currency quoteCurrency, decimal amount) { string currencyPair = baseCurrency.Name + quoteCurrency.Name; List <Fee> feeList = _feeRepository.GetFeeByCurrencyPair(currencyPair); for (int i = 0; i < feeList.Count; i++) { // E.g., if amount == 500 && currentFee element = 1000 if (feeList[i].Amount >= amount) { Fee currentFee = _feeRepository.GetFeeByCurrencyAndAmount(currencyPair, feeList[i].Amount); return(currentFee.PercentageFee); } // If this is not the last element in the list if ((feeList.Count - i) != 1) { // E.g., if amount == 1100 && currentFee = 1000 && currentFee + 1 = 2000 if (feeList[i].Amount <amount && feeList[i + 1].Amount> amount) { Fee currentFee = _feeRepository.GetFeeByCurrencyAndAmount(currencyPair, feeList[i].Amount); return(currentFee.PercentageFee); } } // If this is the last element, that means the amount is greater than or equal to the last percentage element, // so we provide the last element else { if (feeList[i].Amount <= amount) { Fee currentFee = _feeRepository.GetFeeByCurrencyAndAmount(currencyPair, feeList[i].Amount); return(currentFee.PercentageFee); } } } return(0); }