public static OrderBook adaptOrderBook ( final RippleOrderBook rippleOrderBook , final RippleMarketDataParams params , final CurrencyPair currencyPair ) { final String orderBook = rippleOrderBook . getOrderBook ( ) ; // e.g. XRP/BTC+rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B 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 = "" ; // native currency } 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 = "" ; // native currency } 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 ) ; }
Adapts a Ripple OrderBook to an XChange OrderBook object . Counterparties are not mapped since the application calling this should know and keep track of the counterparties it is using in the polling thread .