@Test public void pendingOrderPricesShouldEqualThePricesPassedToTheCut() { mockSignalAndTrend(opt(UP)); mockPrices(opt(new Price(2.0)), opt(new Price(3.0)), opt(new Price(4.0))); cut.checkMarketEntry(eventListener); verify(broker).sendOrder(this.sentPendingOrder.capture(), same(eventListener)); final BasicPendingOrder orderSentToBroker = this.sentPendingOrder.getValue(); assertThat(orderSentToBroker.getEntryPrice()).isEqualTo(new Price(2.0)); assertThat(orderSentToBroker.getCloseConditions().getTakeProfit()).isEqualTo(new Price(3.0)); assertThat(orderSentToBroker.getCloseConditions().getStopLoose()).isEqualTo(new Price(4.0)); }
public Optional<Order> checkMarketEntry(final OrderEventListener eventListener) { if (!(strategy.getEntrySignal().isPresent() && strategy.getEntryPrice().isPresent() && strategy.getTakeProfit().isPresent() && strategy.getStopLoose().isPresent())) { return Optional.empty(); } if (!strategy.getTrend().equals(strategy.getEntrySignal())) { return Optional.empty(); } final OrderType type = strategy.getEntrySignal().get() == UP ? BUY : SELL; final BasicPendingOrder pendingOrder = new MutablePendingOrder().setType(type) .setExecutionCondition(strategy.getEntryCondition()) .setEntryPrice(strategy.getEntryPrice().get()).setCloseConditions(new MutableCloseConditions() .setTakeProfit(strategy.getTakeProfit().get()).setStopLoose(strategy.getStopLoose().get())) .toImmutableBasicPendingOrder(); final OrderManagement orderManagement = broker.sendOrder(pendingOrder, eventListener); return Optional.of(new Order(pendingOrder, orderManagement)); }
PendingOrderCreator { public Optional<Order> checkMarketEntry(final OrderEventListener eventListener) { if (!(strategy.getEntrySignal().isPresent() && strategy.getEntryPrice().isPresent() && strategy.getTakeProfit().isPresent() && strategy.getStopLoose().isPresent())) { return Optional.empty(); } if (!strategy.getTrend().equals(strategy.getEntrySignal())) { return Optional.empty(); } final OrderType type = strategy.getEntrySignal().get() == UP ? BUY : SELL; final BasicPendingOrder pendingOrder = new MutablePendingOrder().setType(type) .setExecutionCondition(strategy.getEntryCondition()) .setEntryPrice(strategy.getEntryPrice().get()).setCloseConditions(new MutableCloseConditions() .setTakeProfit(strategy.getTakeProfit().get()).setStopLoose(strategy.getStopLoose().get())) .toImmutableBasicPendingOrder(); final OrderManagement orderManagement = broker.sendOrder(pendingOrder, eventListener); return Optional.of(new Order(pendingOrder, orderManagement)); } }
PendingOrderCreator { public Optional<Order> checkMarketEntry(final OrderEventListener eventListener) { if (!(strategy.getEntrySignal().isPresent() && strategy.getEntryPrice().isPresent() && strategy.getTakeProfit().isPresent() && strategy.getStopLoose().isPresent())) { return Optional.empty(); } if (!strategy.getTrend().equals(strategy.getEntrySignal())) { return Optional.empty(); } final OrderType type = strategy.getEntrySignal().get() == UP ? BUY : SELL; final BasicPendingOrder pendingOrder = new MutablePendingOrder().setType(type) .setExecutionCondition(strategy.getEntryCondition()) .setEntryPrice(strategy.getEntryPrice().get()).setCloseConditions(new MutableCloseConditions() .setTakeProfit(strategy.getTakeProfit().get()).setStopLoose(strategy.getStopLoose().get())) .toImmutableBasicPendingOrder(); final OrderManagement orderManagement = broker.sendOrder(pendingOrder, eventListener); return Optional.of(new Order(pendingOrder, orderManagement)); } PendingOrderCreator(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); }
PendingOrderCreator { public Optional<Order> checkMarketEntry(final OrderEventListener eventListener) { if (!(strategy.getEntrySignal().isPresent() && strategy.getEntryPrice().isPresent() && strategy.getTakeProfit().isPresent() && strategy.getStopLoose().isPresent())) { return Optional.empty(); } if (!strategy.getTrend().equals(strategy.getEntrySignal())) { return Optional.empty(); } final OrderType type = strategy.getEntrySignal().get() == UP ? BUY : SELL; final BasicPendingOrder pendingOrder = new MutablePendingOrder().setType(type) .setExecutionCondition(strategy.getEntryCondition()) .setEntryPrice(strategy.getEntryPrice().get()).setCloseConditions(new MutableCloseConditions() .setTakeProfit(strategy.getTakeProfit().get()).setStopLoose(strategy.getStopLoose().get())) .toImmutableBasicPendingOrder(); final OrderManagement orderManagement = broker.sendOrder(pendingOrder, eventListener); return Optional.of(new Order(pendingOrder, orderManagement)); } PendingOrderCreator(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); Optional<Order> checkMarketEntry(final OrderEventListener eventListener); }
PendingOrderCreator { public Optional<Order> checkMarketEntry(final OrderEventListener eventListener) { if (!(strategy.getEntrySignal().isPresent() && strategy.getEntryPrice().isPresent() && strategy.getTakeProfit().isPresent() && strategy.getStopLoose().isPresent())) { return Optional.empty(); } if (!strategy.getTrend().equals(strategy.getEntrySignal())) { return Optional.empty(); } final OrderType type = strategy.getEntrySignal().get() == UP ? BUY : SELL; final BasicPendingOrder pendingOrder = new MutablePendingOrder().setType(type) .setExecutionCondition(strategy.getEntryCondition()) .setEntryPrice(strategy.getEntryPrice().get()).setCloseConditions(new MutableCloseConditions() .setTakeProfit(strategy.getTakeProfit().get()).setStopLoose(strategy.getStopLoose().get())) .toImmutableBasicPendingOrder(); final OrderManagement orderManagement = broker.sendOrder(pendingOrder, eventListener); return Optional.of(new Order(pendingOrder, orderManagement)); } PendingOrderCreator(final TradingStrategy<?> strategy, final Broker<BasicPendingOrder> broker); Optional<Order> checkMarketEntry(final OrderEventListener eventListener);  }