@Test(expected = IllegalStateException.class) public void failsWhenTradeWasReceivedBeforeFirstMarketData() { when(indicator1.filterOrder(any())).thenReturn(empty()); when(indicator2.filterOrder(any())).thenReturn(empty()); cut.sendOrder(someOrder, someEventListener); }
@Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { if (!receivedData) { throw new IllegalStateException( "To decide if an order is blocked, the market data stream needs to be recieved but no market data was received yet."); } final List<Failed> blocks = stream(orderFilters).map(guard -> guard.filterOrder(order)) .filter(Optional::isPresent).map(Optional::get).collect(toList()); final Optional<Failed> directlyBlocked = blocks.isEmpty() ? Optional.empty() : Optional.of(new TradingBlocked(blocks)); if (directlyBlocked.isPresent()) { eventListener.orderRejected(directlyBlocked.get()); return NO_OP_ORDER_MANAGEMENT; } return broker.sendOrder(order, eventListener); }
OrderFilteringBroker implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { if (!receivedData) { throw new IllegalStateException( "To decide if an order is blocked, the market data stream needs to be recieved but no market data was received yet."); } final List<Failed> blocks = stream(orderFilters).map(guard -> guard.filterOrder(order)) .filter(Optional::isPresent).map(Optional::get).collect(toList()); final Optional<Failed> directlyBlocked = blocks.isEmpty() ? Optional.empty() : Optional.of(new TradingBlocked(blocks)); if (directlyBlocked.isPresent()) { eventListener.orderRejected(directlyBlocked.get()); return NO_OP_ORDER_MANAGEMENT; } return broker.sendOrder(order, eventListener); } }
OrderFilteringBroker implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { if (!receivedData) { throw new IllegalStateException( "To decide if an order is blocked, the market data stream needs to be recieved but no market data was received yet."); } final List<Failed> blocks = stream(orderFilters).map(guard -> guard.filterOrder(order)) .filter(Optional::isPresent).map(Optional::get).collect(toList()); final Optional<Failed> directlyBlocked = blocks.isEmpty() ? Optional.empty() : Optional.of(new TradingBlocked(blocks)); if (directlyBlocked.isPresent()) { eventListener.orderRejected(directlyBlocked.get()); return NO_OP_ORDER_MANAGEMENT; } return broker.sendOrder(order, eventListener); } @SafeVarargs  OrderFilteringBroker(final Broker<BasicPendingOrder> broker, final OrderFilter<C>... orderFilters); }
OrderFilteringBroker implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { if (!receivedData) { throw new IllegalStateException( "To decide if an order is blocked, the market data stream needs to be recieved but no market data was received yet."); } final List<Failed> blocks = stream(orderFilters).map(guard -> guard.filterOrder(order)) .filter(Optional::isPresent).map(Optional::get).collect(toList()); final Optional<Failed> directlyBlocked = blocks.isEmpty() ? Optional.empty() : Optional.of(new TradingBlocked(blocks)); if (directlyBlocked.isPresent()) { eventListener.orderRejected(directlyBlocked.get()); return NO_OP_ORDER_MANAGEMENT; } return broker.sendOrder(order, eventListener); } @SafeVarargs  OrderFilteringBroker(final Broker<BasicPendingOrder> broker, final OrderFilter<C>... orderFilters); @Override OrderManagement sendOrder(final BasicPendingOrder order,
                                     final OrderEventListener eventListener); @Override void newData(final C candleStick); }
OrderFilteringBroker implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { if (!receivedData) { throw new IllegalStateException( "To decide if an order is blocked, the market data stream needs to be recieved but no market data was received yet."); } final List<Failed> blocks = stream(orderFilters).map(guard -> guard.filterOrder(order)) .filter(Optional::isPresent).map(Optional::get).collect(toList()); final Optional<Failed> directlyBlocked = blocks.isEmpty() ? Optional.empty() : Optional.of(new TradingBlocked(blocks)); if (directlyBlocked.isPresent()) { eventListener.orderRejected(directlyBlocked.get()); return NO_OP_ORDER_MANAGEMENT; } return broker.sendOrder(order, eventListener); } @SafeVarargs  OrderFilteringBroker(final Broker<BasicPendingOrder> broker, final OrderFilter<C>... orderFilters); @Override OrderManagement sendOrder(final BasicPendingOrder order,
                                     final OrderEventListener eventListener); @Override void newData(final C candleStick);  }