use of org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse in project XChange by knowm.
the class BitfinexAdapters method adaptDynamicTradingFees.
/**
* Each element in the response array contains a set of currencies that are at a given fee tier.
* The API returns the fee per currency in each tier and does not make any promises that they are
* all the same, so this adapter will use the fee per currency instead of the fee per tier.
*/
public static Map<CurrencyPair, Fee> adaptDynamicTradingFees(BitfinexTradingFeeResponse[] responses, List<CurrencyPair> currencyPairs) {
Map<CurrencyPair, Fee> result = new HashMap<>();
for (BitfinexTradingFeeResponse response : responses) {
BitfinexTradingFeeResponse.BitfinexTradingFeeResponseRow[] responseRows = response.getTradingFees();
for (BitfinexTradingFeeResponse.BitfinexTradingFeeResponseRow responseRow : responseRows) {
Currency currency = Currency.getInstance(responseRow.getCurrency());
BigDecimal percentToFraction = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(2));
Fee fee = new Fee(responseRow.getMakerFee().multiply(percentToFraction), responseRow.getTakerFee().multiply(percentToFraction));
for (CurrencyPair pair : currencyPairs) {
// Fee is typically assessed in units counter.
if (pair.base.equals(currency)) {
if (result.put(pair, fee) != null) {
throw new IllegalStateException("Fee for currency pair " + pair + " is overspecified");
}
}
}
}
}
return result;
}
use of org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse in project XChange by knowm.
the class BitfinexAdaptersTest method shouldAdaptDynamicTradingFees.
@Test
public void shouldAdaptDynamicTradingFees() throws IOException {
InputStream is = BitfinexFeesJSONTest.class.getResourceAsStream("/v1/account/example-account-info-fees.json");
ObjectMapper mapper = new ObjectMapper();
BitfinexTradingFeeResponse[] readValues = mapper.readValue(is, BitfinexTradingFeeResponse[].class);
assertEquals(2, readValues.length);
List<CurrencyPair> currencyPairs = new ArrayList<CurrencyPair>(Arrays.asList(new CurrencyPair[] { CurrencyPair.BTC_LTC, CurrencyPair.LTC_AUD, CurrencyPair.ETH_BTC, CurrencyPair.DGC_BTC, CurrencyPair.BTC_USD }));
Map<CurrencyPair, Fee> feesPerPair = BitfinexAdapters.adaptDynamicTradingFees(readValues, currencyPairs);
assertEquals(currencyPairs.size(), feesPerPair.size());
BigDecimal point001 = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(3));
BigDecimal point002 = point001.multiply(new BigDecimal(2));
BigDecimal point00025 = new BigDecimal(25).divide(BigDecimal.ONE.scaleByPowerOfTen(5));
BigDecimal point0001 = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(4));
Fee btcLTCFee = feesPerPair.get(CurrencyPair.BTC_LTC);
Fee btcExpectedFee = new Fee(point001, point002);
assertEquals(btcExpectedFee, btcLTCFee);
Fee btcUSDFee = feesPerPair.get(CurrencyPair.BTC_USD);
assertEquals(btcExpectedFee, btcUSDFee);
Fee ltcFee = feesPerPair.get(CurrencyPair.LTC_AUD);
assertEquals(new Fee(point001, point002), ltcFee);
Fee ethFee = feesPerPair.get(CurrencyPair.ETH_BTC);
assertEquals(new Fee(point001, point002), ethFee);
Fee dgcFee = feesPerPair.get(CurrencyPair.DGC_BTC);
assertEquals(new Fee(point00025, point0001), dgcFee);
}
Aggregations