RippleAdapters { public static OrderBook adaptOrderBook( final RippleOrderBook rippleOrderBook, final RippleMarketDataParams params, final CurrencyPair currencyPair) { final String orderBook = rippleOrderBook.getOrderBook(); final String[] splitPair = orderBook.split("/"); final String[] baseSplit = splitPair[0].split("\\+"); final String baseSymbol = baseSplit[0]; if (baseSymbol.equals(currencyPair.base.getCurrencyCode()) == false) { throw new IllegalStateException( String.format( "base symbol in Ripple order book %s does not match requested base %s", orderBook, currencyPair)); } final String baseCounterparty; if (baseSymbol.equals("XRP")) { baseCounterparty = ""; } else { baseCounterparty = baseSplit[1]; } if (baseCounterparty.equals(params.getBaseCounterparty()) == false) { throw new IllegalStateException( String.format( "base counterparty in Ripple order book %s does not match requested counterparty %s", orderBook, params.getBaseCounterparty())); } final String[] counterSplit = splitPair[1].split("\\+"); final String counterSymbol = counterSplit[0]; if (counterSymbol.equals(currencyPair.counter.getCurrencyCode()) == false) { throw new IllegalStateException( String.format( "counter symbol in Ripple order book %s does not match requested base %s", orderBook, currencyPair)); } final String counterCounterparty; if (counterSymbol.equals("XRP")) { counterCounterparty = ""; } else { counterCounterparty = counterSplit[1]; } if (counterCounterparty.equals(params.getCounterCounterparty()) == false) { throw new IllegalStateException( String.format( "counter counterparty in Ripple order book %s does not match requested counterparty %s", orderBook, params.getCounterCounterparty())); } final List<LimitOrder> bids = createOrders( currencyPair, OrderType.BID, rippleOrderBook.getBids(), baseCounterparty, counterCounterparty); final List<LimitOrder> asks = createOrders( currencyPair, OrderType.ASK, rippleOrderBook.getAsks(), baseCounterparty, counterCounterparty); return new OrderBook(null, asks, bids); } private  RippleAdapters(); static AccountInfo adaptAccountInfo(
      final RippleAccountBalances account, final String username); static OrderBook adaptOrderBook(
      final RippleOrderBook rippleOrderBook,
      final RippleMarketDataParams params,
      final CurrencyPair currencyPair); static List<LimitOrder> createOrders(
      final CurrencyPair currencyPair,
      final OrderType orderType,
      final List<RippleOrder> orders,
      final String baseCounterparty,
      final String counterCounterparty); static OpenOrders adaptOpenOrders(
      final RippleAccountOrders rippleOrders, final int scale); static UserTrade adaptTrade(
      final IRippleTradeTransaction trade,
      final TradeHistoryParams params,
      final ITransferFeeSource transferFeeSource,
      final int scale); static UserTrades adaptTrades(
      final Collection<IRippleTradeTransaction> tradesForAccount,
      final TradeHistoryParams params,
      final RippleAccountService accountService,
      final int roundingScale);  }
@Test public void adaptOrderBookTest() throws IOException { final InputStream is = getClass() .getResourceAsStream( "/org/knowm/xchange/ripple/dto/marketdata/example-order-book.json"); final CurrencyPair currencyPair = CurrencyPair.XRP_BTC; final RippleMarketDataParams params = new RippleMarketDataParams(); params.setCounterCounterparty("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"); final ObjectMapper mapper = new ObjectMapper(); final RippleOrderBook rippleOrderBook = mapper.readValue(is, RippleOrderBook.class); final OrderBook orderBook = RippleAdapters.adaptOrderBook(rippleOrderBook, params, currencyPair); assertThat(orderBook.getBids()).hasSize(10); assertThat(orderBook.getAsks()).hasSize(10); final LimitOrder lastBid = orderBook.getBids().get(9); assertThat(lastBid).isInstanceOf(RippleLimitOrder.class); assertThat(lastBid.getCurrencyPair()).isEqualTo(currencyPair); assertThat(((RippleLimitOrder) lastBid).getCounterCounterparty()) .isEqualTo("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"); assertThat(lastBid.getType()).isEqualTo(OrderType.BID); assertThat(lastBid.getId()).isEqualTo("1303704"); assertThat(lastBid.getOriginalAmount()).isEqualTo("66314.537782"); assertThat(lastBid.getLimitPrice()).isEqualTo("0.00003317721777288062"); final LimitOrder firstAsk = orderBook.getAsks().get(0); assertThat(firstAsk).isInstanceOf(RippleLimitOrder.class); assertThat(firstAsk.getCurrencyPair()).isEqualTo(currencyPair); assertThat(((RippleLimitOrder) firstAsk).getCounterCounterparty()) .isEqualTo("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"); assertThat(firstAsk.getType()).isEqualTo(OrderType.ASK); assertThat(firstAsk.getId()).isEqualTo("1011310"); assertThat(firstAsk.getOriginalAmount()).isEqualTo("35447.914936"); assertThat(firstAsk.getLimitPrice()).isEqualTo("0.00003380846624897726"); }