BinanceAdapters { public static Order adaptOrder(BinanceOrder order) { OrderType type = convert(order.side); CurrencyPair currencyPair = adaptSymbol(order.symbol); Order.Builder builder; if (order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.MARKET)) { builder = new MarketOrder.Builder(type, currencyPair); } else if (order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.LIMIT) || order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.LIMIT_MAKER)) { builder = new LimitOrder.Builder(type, currencyPair).limitPrice(order.price); } else { builder = new StopOrder.Builder(type, currencyPair).stopPrice(order.stopPrice); } builder .orderStatus(adaptOrderStatus(order.status)) .originalAmount(order.origQty) .id(Long.toString(order.orderId)) .timestamp(order.getTime()) .cumulativeAmount(order.executedQty); if (order.executedQty.signum() != 0 && order.cummulativeQuoteQty.signum() != 0) { builder.averagePrice( order.cummulativeQuoteQty.divide(order.executedQty, MathContext.DECIMAL32)); } if (order.clientOrderId != null) { builder.flag(BinanceOrderFlags.withClientId(order.clientOrderId)); } return builder.build(); } private  BinanceAdapters(); static String toSymbol(CurrencyPair pair); static String toSymbol(Currency currency); static OrderType convert(OrderSide side); static OrderSide convert(OrderType type); static CurrencyPair convert(String symbol); static long id(String id); static Order.OrderStatus adaptOrderStatus(OrderStatus orderStatus); static OrderType convertType(boolean isBuyer); static CurrencyPair adaptSymbol(String symbol); static Order adaptOrder(BinanceOrder order); static List<Ticker> adaptPriceQuantities(List<BinancePriceQuantity> priceQuantities); static org.knowm.xchange.binance.dto.trade.OrderType adaptOrderType(StopOrder order);  }
@Test public void testFilledMarketOrder() throws Exception { BinanceOrder binanceOrder = ObjectMapperHelper.readValue( BinanceAdaptersTest.class.getResource("/filled-market-order.json"), BinanceOrder.class); Order order = BinanceAdapters.adaptOrder(binanceOrder); assertThat(order).isInstanceOf(MarketOrder.class); MarketOrder marketOrder = (MarketOrder) order; assertThat(marketOrder.getStatus()).isEqualByComparingTo(Order.OrderStatus.FILLED); assertThat(marketOrder.getOriginalAmount()).isEqualByComparingTo("0.10700000"); assertThat(marketOrder.getCumulativeAmount()).isEqualByComparingTo("0.10700000"); assertThat(marketOrder.getRemainingAmount()).isEqualByComparingTo(BigDecimal.ZERO); assertThat(marketOrder.getAveragePrice()).isEqualByComparingTo("0.01858383"); assertThat(marketOrder.getOrderFlags()) .contains(BinanceOrderFlags.withClientId("gzcLIkn86ag3FycOCEl6Vi")); MarketOrder copy = ObjectMapperHelper.viaJSON(marketOrder); assertThat(copy).isEqualToComparingFieldByField(marketOrder); }