@Test public void whenStopLooseForSellOrderIsHigherTheStopLoseShouldNotBeChanged() { exampleOrder.setType(SELL); when(valueCalculator.getStopLoose()).thenReturn(Optional.of(new Price(2.0))); final BasicPendingOrder order = exampleOrder.toImmutableBasicPendingOrder(); cut.manageTrade(new Order(order, orderManagement)); verifyNoMoreInteractions(orderManagement); }
public Optional<Order> manageTrade(final Order trade) { return strategy .getStopLoose() .map(stopLoose -> { final BasicPendingOrder currentTrade = trade.getPendingOrder(); boolean changeStopLoose = false; boolean changeTakeProfit = false; if (currentTrade.getType() == BUY) { if (stopLoose.isGreaterThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } else { if (stopLoose.isLessThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } if (strategy.getTakeProfit().isPresent()) { if (!strategy.getTakeProfit().get().equals(currentTrade.getCloseConditions().getTakeProfit())) { changeTakeProfit = true; } } if (changeStopLoose || changeTakeProfit) { return changeCloseConditions(trade, changeStopLoose ? stopLoose : currentTrade .getCloseConditions().getStopLoose(), changeTakeProfit ? strategy.getTakeProfit().get() : currentTrade.getCloseConditions().getTakeProfit()); } else { return Optional.of(trade); } }).orElse(Optional.of(trade)); }
TradeManager { public Optional<Order> manageTrade(final Order trade) { return strategy .getStopLoose() .map(stopLoose -> { final BasicPendingOrder currentTrade = trade.getPendingOrder(); boolean changeStopLoose = false; boolean changeTakeProfit = false; if (currentTrade.getType() == BUY) { if (stopLoose.isGreaterThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } else { if (stopLoose.isLessThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } if (strategy.getTakeProfit().isPresent()) { if (!strategy.getTakeProfit().get().equals(currentTrade.getCloseConditions().getTakeProfit())) { changeTakeProfit = true; } } if (changeStopLoose || changeTakeProfit) { return changeCloseConditions(trade, changeStopLoose ? stopLoose : currentTrade .getCloseConditions().getStopLoose(), changeTakeProfit ? strategy.getTakeProfit().get() : currentTrade.getCloseConditions().getTakeProfit()); } else { return Optional.of(trade); } }).orElse(Optional.of(trade)); } }
TradeManager { public Optional<Order> manageTrade(final Order trade) { return strategy .getStopLoose() .map(stopLoose -> { final BasicPendingOrder currentTrade = trade.getPendingOrder(); boolean changeStopLoose = false; boolean changeTakeProfit = false; if (currentTrade.getType() == BUY) { if (stopLoose.isGreaterThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } else { if (stopLoose.isLessThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } if (strategy.getTakeProfit().isPresent()) { if (!strategy.getTakeProfit().get().equals(currentTrade.getCloseConditions().getTakeProfit())) { changeTakeProfit = true; } } if (changeStopLoose || changeTakeProfit) { return changeCloseConditions(trade, changeStopLoose ? stopLoose : currentTrade .getCloseConditions().getStopLoose(), changeTakeProfit ? strategy.getTakeProfit().get() : currentTrade.getCloseConditions().getTakeProfit()); } else { return Optional.of(trade); } }).orElse(Optional.of(trade)); } TradeManager(final TradingStrategy<?> strategy); }
TradeManager { public Optional<Order> manageTrade(final Order trade) { return strategy .getStopLoose() .map(stopLoose -> { final BasicPendingOrder currentTrade = trade.getPendingOrder(); boolean changeStopLoose = false; boolean changeTakeProfit = false; if (currentTrade.getType() == BUY) { if (stopLoose.isGreaterThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } else { if (stopLoose.isLessThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } if (strategy.getTakeProfit().isPresent()) { if (!strategy.getTakeProfit().get().equals(currentTrade.getCloseConditions().getTakeProfit())) { changeTakeProfit = true; } } if (changeStopLoose || changeTakeProfit) { return changeCloseConditions(trade, changeStopLoose ? stopLoose : currentTrade .getCloseConditions().getStopLoose(), changeTakeProfit ? strategy.getTakeProfit().get() : currentTrade.getCloseConditions().getTakeProfit()); } else { return Optional.of(trade); } }).orElse(Optional.of(trade)); } TradeManager(final TradingStrategy<?> strategy); Optional<Order> manageTrade(final Order trade); }
TradeManager { public Optional<Order> manageTrade(final Order trade) { return strategy .getStopLoose() .map(stopLoose -> { final BasicPendingOrder currentTrade = trade.getPendingOrder(); boolean changeStopLoose = false; boolean changeTakeProfit = false; if (currentTrade.getType() == BUY) { if (stopLoose.isGreaterThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } else { if (stopLoose.isLessThan(currentTrade.getCloseConditions().getStopLoose())) { changeStopLoose = true; } } if (strategy.getTakeProfit().isPresent()) { if (!strategy.getTakeProfit().get().equals(currentTrade.getCloseConditions().getTakeProfit())) { changeTakeProfit = true; } } if (changeStopLoose || changeTakeProfit) { return changeCloseConditions(trade, changeStopLoose ? stopLoose : currentTrade .getCloseConditions().getStopLoose(), changeTakeProfit ? strategy.getTakeProfit().get() : currentTrade.getCloseConditions().getTakeProfit()); } else { return Optional.of(trade); } }).orElse(Optional.of(trade)); } TradeManager(final TradingStrategy<?> strategy); Optional<Order> manageTrade(final Order trade);  }