public static OpenOrders adaptOpenOrders ( final RippleAccountOrders rippleOrders , final int scale ) { final List < LimitOrder > list = new ArrayList <> ( rippleOrders . getOrders ( ) . size ( ) ) ; for ( final RippleAccountOrdersBody order : rippleOrders . getOrders ( ) ) { final OrderType orderType ; final RippleAmount baseAmount ; final RippleAmount counterAmount ; if ( order . getType ( ) . equals ( "buy" ) ) { // buying: we receive base and pay with counter, taker receives counter and pays with base counterAmount = order . getTakerGets ( ) ; baseAmount = order . getTakerPays ( ) ; orderType = OrderType . BID ; } else { // selling: we receive counter and pay with base, taker receives base and pays with counter baseAmount = order . getTakerGets ( ) ; counterAmount = order . getTakerPays ( ) ; orderType = OrderType . ASK ; } final String baseSymbol = baseAmount . getCurrency ( ) ; final String counterSymbol = counterAmount . getCurrency ( ) ; // need to provide rounding scale to prevent ArithmeticException final BigDecimal price = counterAmount . getValue ( ) . divide ( baseAmount . getValue ( ) , scale , RoundingMode . HALF_UP ) . stripTrailingZeros ( ) ; final CurrencyPair pair = new CurrencyPair ( baseSymbol , counterSymbol ) ; final RippleLimitOrder xchangeOrder = ( RippleLimitOrder ) new RippleLimitOrder . Builder ( orderType , pair ) . baseCounterparty ( baseAmount . getCounterparty ( ) ) . counterCounterparty ( counterAmount . getCounterparty ( ) ) . id ( Long . toString ( order . getSequence ( ) ) ) . limitPrice ( price ) . timestamp ( null ) . originalAmount ( baseAmount . getValue ( ) ) . build ( ) ; list . add ( xchangeOrder ) ; } return new OpenOrders ( list ) ; }
Adapts a Ripple Account Orders object to an XChange OpenOrders object Counterparties set in additional data since there is no other way of the application receiving this information .