LimitOrder extends Order implements Comparable<LimitOrder> { @Override public int compareTo(LimitOrder limitOrder) { final int ret; if (this.getType() == limitOrder.getType()) { ret = this.getLimitPrice().compareTo(limitOrder.getLimitPrice()) * (getType() == OrderType.BID ? -1 : 1); } else { ret = this.getType() == OrderType.BID ? -1 : 1; } return ret; } LimitOrder(
      OrderType type,
      BigDecimal originalAmount,
      Instrument instrument,
      String id,
      Date timestamp,
      BigDecimal limitPrice);  LimitOrder(
      OrderType type,
      BigDecimal originalAmount,
      BigDecimal cumulativeAmount,
      Instrument instrument,
      String id,
      Date timestamp,
      BigDecimal limitPrice);  LimitOrder(
      OrderType type,
      BigDecimal originalAmount,
      Instrument instrument,
      String id,
      Date timestamp,
      BigDecimal limitPrice,
      BigDecimal averagePrice,
      BigDecimal cumulativeAmount,
      BigDecimal fee,
      OrderStatus status);  LimitOrder(
      OrderType type,
      BigDecimal originalAmount,
      Instrument instrument,
      String id,
      Date timestamp,
      BigDecimal limitPrice,
      BigDecimal averagePrice,
      BigDecimal cumulativeAmount,
      BigDecimal fee,
      OrderStatus status,
      String userReference); BigDecimal getLimitPrice(); @Override String toString(); @Override int compareTo(LimitOrder limitOrder); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testSerializeDeserialize() throws IOException { final OrderType type = OrderType.ASK; final BigDecimal originalAmount = new BigDecimal("100.501"); final BigDecimal averagePrice = new BigDecimal("255.00"); final BigDecimal cumulativeAmount = new BigDecimal("0.00"); final CurrencyPair currencyPair = CurrencyPair.BTC_USD; final BigDecimal limitPrice = new BigDecimal("250.34"); final BigDecimal fee = new BigDecimal("22.2"); final Date timestamp = new Date(); final String id = "id"; final Order.OrderStatus status = Order.OrderStatus.FILLED; final LimitOrder original = new LimitOrder( type, originalAmount, currencyPair, id, timestamp, limitPrice, averagePrice, cumulativeAmount, fee, status); original.addOrderFlag(TestFlags.TEST1); original.addOrderFlag(TestFlags.TEST3); LimitOrder jsonCopy = ObjectMapperHelper.viaJSON(original); assertThat(jsonCopy).isEqualToIgnoringGivenFields(original, "cumulativeAmount"); assertTrue(jsonCopy.getCumulativeAmount().compareTo(original.getCumulativeAmount()) == 0); }
@Test public void testCompareTo() { LimitOrder bid1 = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("1")) .build(); LimitOrder anotherBid1 = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("1")) .build(); assertEquals(0, bid1.compareTo(anotherBid1)); assertEquals(0, anotherBid1.compareTo(bid1)); LimitOrder bid2 = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("2")) .build(); assertEquals(-1, bid2.compareTo(bid1)); assertEquals(1, bid1.compareTo(bid2)); LimitOrder ask3 = new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("3")) .build(); LimitOrder anotherAsk3 = new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("3")) .build(); assertEquals(0, ask3.compareTo(anotherAsk3)); assertEquals(0, anotherAsk3.compareTo(ask3)); LimitOrder ask4 = new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("4")) .build(); assertEquals(-1, ask3.compareTo(ask4)); assertEquals(1, ask4.compareTo(ask3)); assertEquals(-1, bid1.compareTo(ask3)); assertEquals(1, ask3.compareTo(bid1)); LimitOrder ask1 = new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USD) .limitPrice(new BigDecimal("1")) .build(); assertEquals(-1, bid1.compareTo(ask1)); assertEquals(1, ask1.compareTo(bid1)); assertEquals(-1, bid2.compareTo(ask1)); assertEquals(1, ask1.compareTo(bid2)); }