@Test public void shouldWritePlacePendingOrderMessagesCorrectly() throws CommunicationException { final MutablePendingOrder order = new MutablePendingOrder().setType(BUY).setExecutionCondition(STOP) .setVolume(new Volume(20, MICRO_LOT)).setEntryPrice(new Price(45.58)) .setCloseConditions(new MutableCloseConditions().setTakeProfit(new Price(54.48)) .setStopLoose(new Price(43.91)).setExpirationDate(Instant.ofEpochSecond(522891))); cut.sendMessage(new PlacePendingOrderMessage(order.toImmutablePendingOrder())); final InOrder inOrder = inOrder(client); inOrder.verify(client).trySendByte(MessageType.PLACE_PENDING_ORDER.getMessageNumber()); inOrder.verify(client).trySendByte((byte) 0b1100); inOrder.verify(client).trySendInteger(20000); inOrder.verify(client).trySendDouble(45.58); inOrder.verify(client).trySendDouble(54.48); inOrder.verify(client).trySendDouble(43.91); inOrder.verify(client).trySendLong(522891); order.setType(SELL); order.setExecutionCondition(DIRECT); order.setCloseConditions( new MutableCloseConditions().setTakeProfit(new Price(54.48)).setStopLoose(new Price(43.91))); cut.sendMessage(new PlacePendingOrderMessage(order.toImmutablePendingOrder())); inOrder.verify(client).trySendByte(MessageType.PLACE_PENDING_ORDER.getMessageNumber()); inOrder.verify(client).trySendByte((byte) 0b0001); }
public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); Message readMessage(); @SuppressWarnings("unchecked") M readMessage(final Class<M> messageClass); void sendMessage(final Message message); @Override String toString(); }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); Message readMessage(); @SuppressWarnings("unchecked") M readMessage(final Class<M> messageClass); void sendMessage(final Message message); @Override String toString();  }