@Test public void whenStopLoosePriceChangesPendingOrderShouldBeReplaced() { when(strategy.getStopLoose()).thenReturn(Optional.of(new Price(3.0))); final Optional<Order> manageBuyOrder = cut.manageOrder(exemplaryBuyOrder, eventListener); verify(exemplaryOrderManagementBuy).closeOrCancelOrder(); verify(broker).sendOrder(this.sentPendingOrder.capture(), same(eventListener)); final BasicPendingOrder newOrder = this.sentPendingOrder.getValue(); assertThat(manageBuyOrder).contains(new Order(newOrder, exemplaryOrderManagementFromBroker)); assertThat(newOrder.getType()).isEqualTo(BUY); assertThat(newOrder.getExecutionCondition()).isEqualTo(STOP); assertThat(newOrder.getEntryPrice()).isEqualTo(new Price(1.0)); assertThat(newOrder.getCloseConditions().getStopLoose()).isEqualTo(new Price(3.0)); assertThat(newOrder.getCloseConditions().getTakeProfit()).isEqualTo(new Price(1.0)); }
public Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener) { if (strategy.getTrend().isPresent()) { final MarketDirection trend = strategy.getTrend().get(); if (trend == UP && order.getPendingOrder().getType() == SELL) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } else if (trend == DOWN && order.getPendingOrder().getType() == BUY) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } } if (stopLooseDifferent(order.getPendingOrder()) || entryPriceDifferent(order.getPendingOrder())) { order.getOrderManagement().closeOrCancelOrder(); return openUpdatedPendingOrder(order.getPendingOrder(), eventListener); } return Optional.of(order); }
PendingOrderManager { public Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener) { if (strategy.getTrend().isPresent()) { final MarketDirection trend = strategy.getTrend().get(); if (trend == UP && order.getPendingOrder().getType() == SELL) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } else if (trend == DOWN && order.getPendingOrder().getType() == BUY) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } } if (stopLooseDifferent(order.getPendingOrder()) || entryPriceDifferent(order.getPendingOrder())) { order.getOrderManagement().closeOrCancelOrder(); return openUpdatedPendingOrder(order.getPendingOrder(), eventListener); } return Optional.of(order); } }
PendingOrderManager { public Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener) { if (strategy.getTrend().isPresent()) { final MarketDirection trend = strategy.getTrend().get(); if (trend == UP && order.getPendingOrder().getType() == SELL) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } else if (trend == DOWN && order.getPendingOrder().getType() == BUY) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } } if (stopLooseDifferent(order.getPendingOrder()) || entryPriceDifferent(order.getPendingOrder())) { order.getOrderManagement().closeOrCancelOrder(); return openUpdatedPendingOrder(order.getPendingOrder(), eventListener); } return Optional.of(order); } PendingOrderManager(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); }
PendingOrderManager { public Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener) { if (strategy.getTrend().isPresent()) { final MarketDirection trend = strategy.getTrend().get(); if (trend == UP && order.getPendingOrder().getType() == SELL) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } else if (trend == DOWN && order.getPendingOrder().getType() == BUY) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } } if (stopLooseDifferent(order.getPendingOrder()) || entryPriceDifferent(order.getPendingOrder())) { order.getOrderManagement().closeOrCancelOrder(); return openUpdatedPendingOrder(order.getPendingOrder(), eventListener); } return Optional.of(order); } PendingOrderManager(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener); }
PendingOrderManager { public Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener) { if (strategy.getTrend().isPresent()) { final MarketDirection trend = strategy.getTrend().get(); if (trend == UP && order.getPendingOrder().getType() == SELL) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } else if (trend == DOWN && order.getPendingOrder().getType() == BUY) { order.getOrderManagement().closeOrCancelOrder(); return Optional.empty(); } } if (stopLooseDifferent(order.getPendingOrder()) || entryPriceDifferent(order.getPendingOrder())) { order.getOrderManagement().closeOrCancelOrder(); return openUpdatedPendingOrder(order.getPendingOrder(), eventListener); } return Optional.of(order); } PendingOrderManager(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); Optional<Order> manageOrder(final Order order, final OrderEventListener eventListener);  }