KrakenAdapters { protected static FeeTier[] adaptFeeTiers(List<KrakenFee> makerFees, List<KrakenFee> takerFees) { Collections.sort(makerFees); Collections.sort(takerFees); List<FeeTier> resultFeeTiers = new ArrayList<FeeTier>(); int makerFeeIdx = 0; int takerFeeIdx = 0; while (makerFeeIdx < makerFees.size() || takerFeeIdx < takerFees.size()) { int curMakerIdx = Math.min(makerFeeIdx, makerFees.size() - 1); int curTakerIdx = Math.min(takerFeeIdx, takerFees.size() - 1); BigDecimal quantityMaker = makerFees.get(curMakerIdx).getVolume(); BigDecimal quantityTaker = takerFees.get(curTakerIdx).getVolume(); BigDecimal resultQuantity = null; BigDecimal resultMakerFee = null; BigDecimal resultTakerFee = null; int makerVolCompTakerVol = quantityMaker.compareTo(quantityTaker); if ((makerVolCompTakerVol > 0 || makerFeeIdx >= makerFees.size()) && takerFeeIdx < takerFees.size()) { if (makerFeeIdx < 1) { throw new IllegalStateException( "Kraken exchange specified fee tiers such that the maker fee was unspecified before a nonzero quantity was traded."); } KrakenFee takerFeeData = takerFees.get(curTakerIdx); resultTakerFee = takerFeeData.getPercentFee(); resultMakerFee = makerFees.get(makerFeeIdx - 1).getPercentFee(); resultQuantity = takerFeeData.getVolume(); takerFeeIdx++; } else if ((makerVolCompTakerVol < 0 || takerFeeIdx >= takerFees.size()) && makerFeeIdx < makerFees.size()) { if (takerFeeIdx < 1) { throw new IllegalStateException( "Kraken exchange specified fee tiers such that the taker fee was unspecified before a nonzero quantity was traded."); } KrakenFee makerFeeData = makerFees.get(curMakerIdx); resultMakerFee = makerFeeData.getPercentFee(); resultTakerFee = takerFees.get(takerFeeIdx - 1).getPercentFee(); resultQuantity = makerFeeData.getVolume(); makerFeeIdx++; } else { KrakenFee makerFeeData = makerFees.get(curMakerIdx); resultMakerFee = makerFeeData.getPercentFee(); resultTakerFee = takerFees.get(curTakerIdx).getPercentFee(); resultQuantity = makerFeeData.getVolume(); takerFeeIdx++; makerFeeIdx++; } resultFeeTiers.add( new FeeTier( resultQuantity, new Fee(resultMakerFee.movePointLeft(2), resultTakerFee.movePointLeft(2)))); } return resultFeeTiers.toArray(new FeeTier[resultFeeTiers.size()]); }  static OrderBook adaptOrderBook(KrakenDepth krakenDepth, CurrencyPair currencyPair); static OrdersContainer adaptOrders(
      List<KrakenPublicOrder> orders, CurrencyPair currencyPair, OrderType orderType); static List<Order> adaptOrders(Map<String, KrakenOrder> krakenOrdersMap); static Order adaptOrder(String orderId, KrakenOrder krakenOrder); static LimitOrder adaptOrder(
      KrakenPublicOrder order, OrderType orderType, CurrencyPair currencyPair); static Ticker adaptTicker(KrakenTicker krakenTicker, CurrencyPair currencyPair); static List<Ticker> adaptTickers(Map<String, KrakenTicker> krackenTickers); static Trades adaptTrades(
      List<KrakenPublicTrade> krakenTrades, CurrencyPair currencyPair, long last); static Trade adaptTrade(KrakenPublicTrade krakenPublicTrade, CurrencyPair currencyPair); static Wallet adaptWallet(Map<String, BigDecimal> krakenWallet); static Set<CurrencyPair> adaptCurrencyPairs(Collection<String> krakenCurrencyPairs); static Currency adaptCurrency(String krakenCurrencyCode); static CurrencyPair adaptCurrencyPair(String krakenCurrencyPair); static OpenOrders adaptOpenOrders(Map<String, KrakenOrder> krakenOrders); static UserTrades adaptTradesHistory(Map<String, KrakenTrade> krakenTrades); static KrakenUserTrade adaptTrade(KrakenTrade krakenTrade, String tradeId); static OrderType adaptOrderType(KrakenType krakenType); static String adaptKrakenDepositAddress(KrakenDepositAddress[] krakenDepositAddress); static String adaptOrderId(KrakenOrderResponse orderResponse); static ExchangeMetaData adaptToExchangeMetaData(
      ExchangeMetaData originalMetaData,
      Map<String, KrakenAssetPair> krakenPairs,
      Map<String, KrakenAsset> krakenAssets); static List<FundingRecord> adaptFundingHistory(
      Map<String, KrakenLedger> krakenLedgerInfo); static OrderStatus adaptOrderStatus(KrakenOrderStatus status);  }
@Test public void testAdaptFeeTiers1() { List<KrakenFee> krakenMakerFees = new ArrayList<KrakenFee>(); List<KrakenFee> krakenTakerFees = new ArrayList<KrakenFee>(); krakenMakerFees.add(new KrakenFee(BigDecimal.TEN, BigDecimal.ONE)); krakenTakerFees.add(new KrakenFee(BigDecimal.TEN, new BigDecimal(2))); krakenMakerFees.add(new KrakenFee(new BigDecimal(45), new BigDecimal(0.5))); krakenTakerFees.add(new KrakenFee(new BigDecimal(30), new BigDecimal(0.75))); FeeTier[] adaptedFeeTiers = KrakenAdapters.adaptFeeTiers(krakenMakerFees, krakenTakerFees); assertThat(adaptedFeeTiers.length).isEqualTo(3); assertThat(adaptedFeeTiers[0].beginQuantity).isEqualByComparingTo(BigDecimal.TEN); assertThat(adaptedFeeTiers[0].fee.getMakerFee()) .isEqualByComparingTo(BigDecimal.ONE.movePointLeft(2)); assertThat(adaptedFeeTiers[0].fee.getTakerFee()) .isEqualByComparingTo(new BigDecimal(2).movePointLeft(2)); assertThat(adaptedFeeTiers[1].beginQuantity).isEqualByComparingTo(new BigDecimal(30)); assertThat(adaptedFeeTiers[1].fee.getMakerFee()) .isEqualByComparingTo(BigDecimal.ONE.movePointLeft(2)); assertThat(adaptedFeeTiers[1].fee.getTakerFee()) .isEqualByComparingTo(new BigDecimal(0.75).movePointLeft(2)); assertThat(adaptedFeeTiers[2].beginQuantity).isEqualByComparingTo(new BigDecimal(45)); assertThat(adaptedFeeTiers[2].fee.getMakerFee()) .isEqualByComparingTo(new BigDecimal(0.5).movePointLeft(2)); assertThat(adaptedFeeTiers[2].fee.getTakerFee()) .isEqualByComparingTo(new BigDecimal(0.75).movePointLeft(2)); }