BittrexAdapters { public static LimitOrder adaptOrder(BittrexOrderBase order, OrderStatus status) { OrderType type = order.getOrderType().equalsIgnoreCase("LIMIT_SELL") ? OrderType.ASK : OrderType.BID; String[] currencies = order.getExchange().split("-"); CurrencyPair pair = new CurrencyPair(currencies[1], currencies[0]); return new LimitOrder.Builder(type, pair) .originalAmount(order.getQuantity()) .id(order.getOrderUuid()) .timestamp(order.getOpened()) .limitPrice(order.getLimit()) .averagePrice(order.getPricePerUnit()) .cumulativeAmount( order.getQuantityRemaining() == null ? null : order.getQuantity().subtract(order.getQuantityRemaining())) .fee(order.getCommissionPaid()) .orderStatus(status) .build(); } private  BittrexAdapters(); static List<CurrencyPair> adaptCurrencyPairs(Collection<BittrexSymbol> bittrexSymbol); static CurrencyPair adaptCurrencyPair(BittrexSymbol bittrexSymbol); static List<LimitOrder> adaptOpenOrders(List<BittrexOpenOrder> bittrexOpenOrders); static LimitOrder adaptOrder(BittrexOrderBase order, OrderStatus status); static List<LimitOrder> adaptOrders(
      BittrexLevel[] orders, CurrencyPair currencyPair, String orderType, String id, int depth); static LimitOrder adaptOrder(
      BigDecimal amount,
      BigDecimal price,
      CurrencyPair currencyPair,
      String orderTypeString,
      String id); static LimitOrder adaptOrder(BittrexOrder order); static LimitOrder adaptOrder(BittrexOpenOrder order); static Trade adaptTrade(BittrexTrade trade, CurrencyPair currencyPair); static Trades adaptTrades(List<BittrexTrade> trades, CurrencyPair currencyPair); static Ticker adaptTicker(BittrexMarketSummary marketSummary, CurrencyPair currencyPair); static Wallet adaptWallet(List<BittrexBalance> balances); static Balance adaptBalance(BittrexBalance balance); static List<UserTrade> adaptUserTrades(List<BittrexUserTrade> bittrexUserTrades); static UserTrade adaptUserTrade(BittrexUserTrade trade); static ExchangeMetaData adaptMetaData(
      List<BittrexSymbol> rawSymbols, ExchangeMetaData metaData); static List<FundingRecord> adaptDepositRecords(
      List<BittrexDepositHistory> bittrexFundingHistories); static List<FundingRecord> adaptWithdrawalRecords(
      List<BittrexWithdrawalHistory> bittrexFundingHistories); static final Logger log; }
@Test public void testAdaptBittrexOrderIsNew() { BittrexOrder order = new BittrexOrder( null, ORDER_UUID, "USDT-ETH", "LIMIT_SELL", QUANTITY, QUANTITY, LIMIT_PRICE, null, null, null, null, FEE, null, AVERAGE_PRICE, null, null, true, null, false, null, null, null, null); LimitOrder adaptedOrder = BittrexAdapters.adaptOrder(order); assertEquals(ORDER_UUID, adaptedOrder.getId()); assertEquals(CurrencyPair.ETH_USDT, adaptedOrder.getCurrencyPair()); assertEquals(OrderType.ASK, adaptedOrder.getType()); assertEquals(QUANTITY, adaptedOrder.getOriginalAmount()); assertEquals(BigDecimal.ZERO, adaptedOrder.getCumulativeAmount().stripTrailingZeros()); assertEquals(LIMIT_PRICE, adaptedOrder.getLimitPrice()); assertEquals(FEE, adaptedOrder.getFee()); assertEquals(AVERAGE_PRICE, adaptedOrder.getAveragePrice()); assertEquals(Order.OrderStatus.NEW, adaptedOrder.getStatus()); }
@Test public void testAdaptBittrexOpenOrderIsNew() { BittrexOpenOrder order = new BittrexOpenOrder( null, ORDER_UUID, "USDT-ETH", "LIMIT_SELL", QUANTITY, QUANTITY, LIMIT_PRICE, FEE, null, AVERAGE_PRICE, null, null, false, null, null, null, null); LimitOrder adaptedOrder = BittrexAdapters.adaptOrder(order); assertEquals(ORDER_UUID, adaptedOrder.getId()); assertEquals(CurrencyPair.ETH_USDT, adaptedOrder.getCurrencyPair()); assertEquals(OrderType.ASK, adaptedOrder.getType()); assertEquals(QUANTITY, adaptedOrder.getOriginalAmount()); assertEquals(BigDecimal.ZERO, adaptedOrder.getCumulativeAmount().stripTrailingZeros()); assertEquals(LIMIT_PRICE, adaptedOrder.getLimitPrice()); assertEquals(FEE, adaptedOrder.getFee()); assertEquals(AVERAGE_PRICE, adaptedOrder.getAveragePrice()); assertEquals(Order.OrderStatus.NEW, adaptedOrder.getStatus()); }
@Test public void testAdaptBittrexOrderIsPartiallyFilled() { BittrexOrder order = new BittrexOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, new BigDecimal("100.00"), null, null, null, null, null, null, null, null, null, null, true, null, false, null, null, null, null); assertEquals(Order.OrderStatus.PARTIALLY_FILLED, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptBittrexOpenOrderIsPartiallyFilled() { BittrexOpenOrder order = new BittrexOpenOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, new BigDecimal("100.31"), null, null, null, null, null, null, false, null, null, null, null); assertEquals(Order.OrderStatus.PARTIALLY_FILLED, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptBittrexOrderIsCancelPending() { BittrexOrder order = new BittrexOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, new BigDecimal("100.00"), null, null, null, null, null, null, null, null, null, null, true, null, true, null, null, null, null); assertEquals(Order.OrderStatus.PENDING_CANCEL, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptBittrexOpenOrderIsCanceledPending() { BittrexOpenOrder order = new BittrexOpenOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, QUANTITY, null, null, null, null, null, null, true, null, null, null, null); assertEquals(Order.OrderStatus.PENDING_CANCEL, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptBittrexOrderIsCanceled() { BittrexOrder order = new BittrexOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, new BigDecimal("100.00"), null, null, null, null, null, null, null, null, null, null, false, null, true, null, null, null, null); assertEquals(Order.OrderStatus.CANCELED, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptBittrexOrderIsFilled() { BittrexOrder order = new BittrexOrder( null, null, "USDT-ETH", "LIMIT_SELL", QUANTITY, new BigDecimal("0E-8"), null, null, null, null, null, null, null, null, null, null, false, null, false, null, null, null, null); assertEquals(Order.OrderStatus.FILLED, BittrexAdapters.adaptOrder(order).getStatus()); }
@Test public void testAdaptLimitOrder() throws IOException { InputStream is = BittrexAdaptersTest.class.getResourceAsStream( "/org/knowm/xchange/bittrex/dto/trade/order/example-limit-buy-order.json"); ObjectMapper mapper = new ObjectMapper(); JavaType responseType = mapper .getTypeFactory() .constructParametricType(BittrexBaseResponse.class, BittrexOrder.class); BittrexBaseResponse<BittrexOrder> bittrexOrderResponse = mapper.readValue(is, responseType); Order order = BittrexAdapters.adaptOrder(bittrexOrderResponse.getResult()); assertThat(order.getId()).isEqualTo("0cb4c4e4-bdc7-4e13-8c13-430e587d2cc1"); assertThat(order.getAveragePrice()).isNull(); assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("0.00000000")); assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.LTC_BTC); assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.NEW); assertThat(LimitOrder.class.isAssignableFrom(order.getClass())); }