@Test public void sendAllNecessaryDataWhenRequestingMoney() { cut.sendOrder(someOrder, someEventListener); final Price expectedLooseOnStopLoose = new Price(5); verify(moneyManagement).requestVolume(SOME_FOREX_SYMBOL, SOME_PRICE, expectedLooseOnStopLoose, SOME_STEP_SIZE); }
@Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { final Price lastPrice = lastMarketData.orElseThrow(() -> new IllegalStateException( "An order was send before the current value of the traded symbol was passed to this instance.")); final Price difference = new Price( Math.abs(order.getEntryPrice().asPipette() - order.getCloseConditions().getStopLoose().asPipette())); final Optional<UsedVolumeManagement> volumeManagement = volumeLender.requestVolume(forexSymbol, lastPrice, difference, allowedStepSize); if (volumeManagement.isPresent()) { final VolumeReturner returner = new VolumeReturner(volumeManagement.get(), eventListener); final OrderManagement origMgmnt = broker.sendOrder(new MutablePendingOrder(order) .setVolume(volumeManagement.get().getVolume()).toImmutablePendingOrder(), returner); returner.setOrderManagement(origMgmnt); return returner; } else { eventListener.orderRejected(NO_VOLUME); return NO_OP_ORDER_MANAGEMENT; } }
StrategyMoneyManagement implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { final Price lastPrice = lastMarketData.orElseThrow(() -> new IllegalStateException( "An order was send before the current value of the traded symbol was passed to this instance.")); final Price difference = new Price( Math.abs(order.getEntryPrice().asPipette() - order.getCloseConditions().getStopLoose().asPipette())); final Optional<UsedVolumeManagement> volumeManagement = volumeLender.requestVolume(forexSymbol, lastPrice, difference, allowedStepSize); if (volumeManagement.isPresent()) { final VolumeReturner returner = new VolumeReturner(volumeManagement.get(), eventListener); final OrderManagement origMgmnt = broker.sendOrder(new MutablePendingOrder(order) .setVolume(volumeManagement.get().getVolume()).toImmutablePendingOrder(), returner); returner.setOrderManagement(origMgmnt); return returner; } else { eventListener.orderRejected(NO_VOLUME); return NO_OP_ORDER_MANAGEMENT; } } }
StrategyMoneyManagement implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { final Price lastPrice = lastMarketData.orElseThrow(() -> new IllegalStateException( "An order was send before the current value of the traded symbol was passed to this instance.")); final Price difference = new Price( Math.abs(order.getEntryPrice().asPipette() - order.getCloseConditions().getStopLoose().asPipette())); final Optional<UsedVolumeManagement> volumeManagement = volumeLender.requestVolume(forexSymbol, lastPrice, difference, allowedStepSize); if (volumeManagement.isPresent()) { final VolumeReturner returner = new VolumeReturner(volumeManagement.get(), eventListener); final OrderManagement origMgmnt = broker.sendOrder(new MutablePendingOrder(order) .setVolume(volumeManagement.get().getVolume()).toImmutablePendingOrder(), returner); returner.setOrderManagement(origMgmnt); return returner; } else { eventListener.orderRejected(NO_VOLUME); return NO_OP_ORDER_MANAGEMENT; } } StrategyMoneyManagement(final Broker<PendingOrder> broker, final VolumeLender volumeLender,
                            final ForexSymbol forexSymbol, final Volume allowedStepSize); }
StrategyMoneyManagement implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { final Price lastPrice = lastMarketData.orElseThrow(() -> new IllegalStateException( "An order was send before the current value of the traded symbol was passed to this instance.")); final Price difference = new Price( Math.abs(order.getEntryPrice().asPipette() - order.getCloseConditions().getStopLoose().asPipette())); final Optional<UsedVolumeManagement> volumeManagement = volumeLender.requestVolume(forexSymbol, lastPrice, difference, allowedStepSize); if (volumeManagement.isPresent()) { final VolumeReturner returner = new VolumeReturner(volumeManagement.get(), eventListener); final OrderManagement origMgmnt = broker.sendOrder(new MutablePendingOrder(order) .setVolume(volumeManagement.get().getVolume()).toImmutablePendingOrder(), returner); returner.setOrderManagement(origMgmnt); return returner; } else { eventListener.orderRejected(NO_VOLUME); return NO_OP_ORDER_MANAGEMENT; } } StrategyMoneyManagement(final Broker<PendingOrder> broker, final VolumeLender volumeLender,
                            final ForexSymbol forexSymbol, final Volume allowedStepSize); @Override OrderManagement sendOrder(final BasicPendingOrder order,
                                     final OrderEventListener eventListener); @Override void newData(final C marketData); }
StrategyMoneyManagement implements Broker<BasicPendingOrder>, MarketDataListener<C> { @Override public OrderManagement sendOrder(final BasicPendingOrder order, final OrderEventListener eventListener) { final Price lastPrice = lastMarketData.orElseThrow(() -> new IllegalStateException( "An order was send before the current value of the traded symbol was passed to this instance.")); final Price difference = new Price( Math.abs(order.getEntryPrice().asPipette() - order.getCloseConditions().getStopLoose().asPipette())); final Optional<UsedVolumeManagement> volumeManagement = volumeLender.requestVolume(forexSymbol, lastPrice, difference, allowedStepSize); if (volumeManagement.isPresent()) { final VolumeReturner returner = new VolumeReturner(volumeManagement.get(), eventListener); final OrderManagement origMgmnt = broker.sendOrder(new MutablePendingOrder(order) .setVolume(volumeManagement.get().getVolume()).toImmutablePendingOrder(), returner); returner.setOrderManagement(origMgmnt); return returner; } else { eventListener.orderRejected(NO_VOLUME); return NO_OP_ORDER_MANAGEMENT; } } StrategyMoneyManagement(final Broker<PendingOrder> broker, final VolumeLender volumeLender,
                            final ForexSymbol forexSymbol, final Volume allowedStepSize); @Override OrderManagement sendOrder(final BasicPendingOrder order,
                                     final OrderEventListener eventListener); @Override void newData(final C marketData);  }