LgoTradeService extends LgoTradeServiceRaw implements TradeService { @Override public void verifyOrder(MarketOrder marketOrder) { LgoProduct product = getProduct(marketOrder.getCurrencyPair()); LgoProductCurrency currencyToCheck = OrderType.BID.equals(marketOrder.getType()) ? product.getQuote() : product.getBase(); if (currencyToCheck.getLimits().getMin().compareTo(marketOrder.getRemainingAmount()) > 0) { throw new IllegalArgumentException("Quantity to low"); } if (currencyToCheck.getLimits().getMax().compareTo(marketOrder.getRemainingAmount()) < 0) { throw new IllegalArgumentException("Quantity to high"); } } LgoTradeService(LgoExchange exchange, LgoKeyService keyService); @Override UserTrades getTradeHistory(TradeHistoryParams params); @Override TradeHistoryParams createTradeHistoryParams(); @Override void verifyOrder(MarketOrder marketOrder); @Override void verifyOrder(LimitOrder limitOrder); @Override String placeLimitOrder(LimitOrder limitOrder); @Override String placeMarketOrder(MarketOrder marketOrder); @Override boolean cancelOrder(CancelOrderParams orderParams); @Override boolean cancelOrder(String orderId);  }
@Test public void acceptsCorrectLimitOrder() { tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("3"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal(7000))); }
@Test public void acceptsCorrectMarketOrder() { tradeService.verifyOrder( new MarketOrder(OrderType.BID, new BigDecimal("1000"), CurrencyPair.BTC_USD, new Date())); }
@Test public void cannotPlaceLimitOrderWithToLowBaseAmount() { ThrowingCallable check = () -> tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("0.00000001"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal(7000))); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unsupported amount scale 8"); }
@Test public void cannotPlaceLimitOrderWithToHighBaseAmount() { ThrowingCallable check = () -> tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("1001"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal(7000))); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Order amount more than maximum"); }
@Test public void cannotPlaceLimitOrderWithToLowPrice() { ThrowingCallable check = () -> tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("10"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal(9))); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Order price to low"); }
@Test public void cannotPlaceLimitOrderWithToHighPrice() { ThrowingCallable check = () -> tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("10"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal(1000001))); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Order price to high"); }
@Test public void cannotPlaceLimitOrderWithInvalidPriceIncrement() { ThrowingCallable check = () -> tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("10"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal("100.05"))); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unsupported price scale 2"); }
@Test public void canPlaceLimitOrderWithValidPriceIncrementAndScaleGreaterThan0() { tradeService.verifyOrder( new LimitOrder( OrderType.ASK, new BigDecimal("10"), CurrencyPair.BTC_USD, "", new Date(), new BigDecimal("100.1"))); assertThat(true).describedAs("No exception thrown").isTrue(); }
@Test public void cannotPlaceBidMarketOrderWithAmountToLow() { ThrowingCallable check = () -> tradeService.verifyOrder( new MarketOrder( OrderType.BID, new BigDecimal("0.00001"), CurrencyPair.BTC_USD, new Date())); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Quantity to low"); }
@Test public void cannotPlaceBidMarketOrderWithAmountToHigh() { ThrowingCallable check = () -> tradeService.verifyOrder( new MarketOrder( OrderType.BID, new BigDecimal("1000001"), CurrencyPair.BTC_USD, new Date())); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Quantity to high"); }
@Test public void cannotPlaceAskMarketOrderWithAmountToLow() { ThrowingCallable check = () -> tradeService.verifyOrder( new MarketOrder( OrderType.ASK, new BigDecimal("0.00001"), CurrencyPair.BTC_USD, new Date())); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Quantity to low"); }
@Test public void cannotPlaceAskMarketOrderWithAmountToHigh() { ThrowingCallable check = () -> tradeService.verifyOrder( new MarketOrder( OrderType.ASK, new BigDecimal("1001"), CurrencyPair.BTC_USD, new Date())); assertThatThrownBy(check) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Quantity to high"); }