LgoStreamingTradeService implements StreamingTradeService { @Override public Observable<Order> getOrderChanges(CurrencyPair currencyPair, Object... args) { return getOrderBatchChanges(currencyPair).flatMap(Observable::fromIterable); } LgoStreamingTradeService(
      LgoStreamingService streamingService,
      LgoKeyService keyService,
      LgoSignatureService signatureService,
      SynchronizedValueFactory<Long> nonceFactory); @Override Observable<Order> getOrderChanges(CurrencyPair currencyPair, Object... args); Observable<OpenOrders> getOpenOrders(CurrencyPair currencyPair); Observable<Collection<Order>> getOrderBatchChanges(CurrencyPair currencyPair); @Override Observable<UserTrade> getUserTrades(CurrencyPair currencyPair, Object... args); Observable<LgoOrderEvent> getRawAllOrderEvents(Collection<CurrencyPair> currencyPairs); Observable<LgoOrderEvent> getRawReceivedOrderEvents(); Observable<LgoOrderEvent> getRawBatchOrderEvents(CurrencyPair currencyPair); String placeMarketOrder(MarketOrder marketOrder); String placeLimitOrder(LimitOrder limitOrder); boolean cancelOrder(String orderId);  }
@Test public void it_handles_order_changes() throws IOException, ParseException { JsonNode snapshot = TestUtils.getJsonContent("/trade/order-changes-snapshot.json"); JsonNode update = TestUtils.getJsonContent("/trade/order-changes-update.json"); when(streamingService.subscribeChannel(anyString())) .thenReturn(Observable.just(snapshot, update)); Observable<Order> observable = service.getOrderChanges(CurrencyPair.BTC_USD); verify(streamingService).subscribeChannel("user-BTC-USD"); Date date1 = dateFormat.parse("2019-07-23T15:36:14.304Z"); Date date2 = dateFormat.parse("2019-07-18T12:24:21.891Z"); Date date3 = dateFormat.parse("2019-07-24T08:37:19.116Z"); LimitOrder order1 = createOrder( Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156389617430400001", date1, new BigDecimal("6000.0000"), Order.OrderStatus.NEW); LimitOrder order2 = createOrder( Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.NEW); LimitOrder order2Matched = createOrder( Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.40000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.PARTIALLY_FILLED); order2Matched.setFee(new BigDecimal("0.2388")); LimitOrder order2Matched2 = createOrder( Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("1.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.PARTIALLY_FILLED); order2Matched2.setFee(new BigDecimal("0.6988")); LimitOrder order2Filled = createOrder( Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("1.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.FILLED); order2Filled.setFee(new BigDecimal("0.6988")); LimitOrder order3Pending = createOrder( Order.OrderType.BID, new BigDecimal("2.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156395743911600001", date3, new BigDecimal("8000.0000"), Order.OrderStatus.PENDING_NEW); LimitOrder order3Open = createOrder( Order.OrderType.BID, new BigDecimal("2.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156395743911600001", date3, new BigDecimal("8000.0000"), Order.OrderStatus.NEW); ArrayList<Order> orderChanges = Lists.newArrayList(observable.blockingIterable()); assertThat(orderChanges).hasSize(7); assertThat(orderChanges.get(0)).usingRecursiveComparison().isEqualTo(order1); assertThat(orderChanges.get(1)).usingRecursiveComparison().isEqualTo(order2); assertThat(orderChanges.get(2)).usingRecursiveComparison().isEqualTo(order3Pending); assertThat(orderChanges.get(3)).usingRecursiveComparison().isEqualTo(order3Open); assertThat(orderChanges.get(4)).usingRecursiveComparison().isEqualTo(order2Matched); assertThat(orderChanges.get(5)).usingRecursiveComparison().isEqualTo(order2Matched2); assertThat(orderChanges.get(6)).usingRecursiveComparison().isEqualTo(order2Filled); }