static Message get(FIXMessage message) { List<Field> fields = new ArrayList<>(); String msgType = null; for (int i = 0; i < message.getFieldCount(); i++) { int tag = message.tagAt(i); String value = message.valueAt(i).asString(); if (tag == MsgType) msgType = value; else fields.add(new Field(tag, value)); } if (msgType == null) throw new IllegalArgumentException("MsgType(35) missing"); return new Message(msgType, fields); }
private void handleTestRequest(FIXMessage message) throws IOException { FIXValue testReqId = message.valueOf(TestReqID); if (testReqId == null) { sendReject(message.getMsgSeqNum(), RequiredTagMissing, "TestReqID(112) not found"); return; } sendHeartbeat(testReqId); }
@Setup(Level.Iteration) public void prepare() { message = new FIXMessage(32, 32); format(); buffer = ByteBuffer.allocateDirect(1024); message.put(buffer); buffer.flip(); }
@Override public void message(FIXMessage message) throws IOException { FIXValue msgType = message.getMsgType(); for (int i = 0; i < message.getFieldCount(); i++) { switch (message.tagAt(i)) { case ClOrdID: clOrdId.set(message.valueAt(i)); break; case Symbol: symbol.set(message.valueAt(i)); break; case Side: side.set(message.valueAt(i)); break; case OrderQty: orderQty.set(message.valueAt(i)); break; case Price: price.set(message.valueAt(i)); break; connection.sendReject(message.getMsgSeqNum(), 1, "ClOrdID(11) not found"); return; connection.sendReject(message.getMsgSeqNum(), 1, "Symbol(55) not found"); return; connection.sendReject(message.getMsgSeqNum(), 1, "OrderQty(38) not found"); return;
/** * Construct a new message container from a string representation. * * <p><strong>Note.</strong> This method allocates memory.</p> * * @param s a string representation * @return a message container */ public static FIXMessage fromString(String s) { String[][] fields = Stream.of(s.split("\\|")) .map(field -> field.split("=")) .toArray(String[][]::new); int maxValueLength = Stream.of(fields) .mapToInt(field -> field[1].length()) .max() .orElse(0); FIXMessage message = new FIXMessage(fields.length, maxValueLength + 1); for (String[] field : fields) { int tag = Integer.parseInt(field[0]); String value = field[1]; message.addField(tag).setString(value); } return message; }
@Override public void message(FIXMessage message) throws IOException { long msgSeqNum = message.getMsgSeqNum(); if (msgSeqNum == 0) { msgSeqNumNotFound(); FIXValue msgType = message.getMsgType(); if (msgType == null) { msgTypeNotFound();
private void invalidMsgType(FIXMessage message) throws IOException { fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.InvalidMsgType, "Invalid MsgType(35)"); }
/** * Create a message container. * * @return a message container */ public FIXMessage create() { return new FIXMessage(config.getMaxFieldCount(), config.getFieldCapacity()); }
@Benchmark public void put() { message.put(buffer); buffer.flip(); }
@Benchmark public FIXMessage get() throws FIXMessageOverflowException, FIXValueOverflowException { message.get(buffer); buffer.flip(); return message; }
@Override public void message(FIXMessage message) throws IOException { FIXValue msgType = message.getMsgType(); if (msgType.length() != 1) { invalidMsgType(message); return; } switch (msgType.asChar()) { case NewOrderSingle: newOrderSingle(message); break; case OrderCancelReplaceRequest: orderCancel(message, OrderCancelReplaceRequest); break; case OrderCancelRequest: orderCancel(message, OrderCancelRequest); break; default: invalidMsgType(message); break; } }
/** * Construct a new message container from a string representation. * * <p><strong>Note.</strong> This method allocates memory.</p> * * @param s a string representation * @return a message container */ public static FIXMessage fromString(String s) { String[][] fields = Stream.of(s.split("\\|")) .map(field -> field.split("=")) .toArray(String[][]::new); int maxValueLength = Stream.of(fields) .mapToInt(field -> field[1].length()) .max() .orElse(0); FIXMessage message = new FIXMessage(fields.length, maxValueLength + 1); for (String[] field : fields) { int tag = Integer.parseInt(field[0]); String value = field[1]; message.addField(tag).setString(value); } return message; }
@Override public void message(FIXMessage message) throws IOException { long msgSeqNum = message.getMsgSeqNum(); if (msgSeqNum == 0) { sendLogout("MsgSeqNum(34) not found"); FIXValue msgType = message.getMsgType(); if (msgType == null) { statusListener.close(FIXConnection.this, "MsgType(35) not found");
private void requiredTagMissing(FIXMessage message, String text) throws IOException { fix.sendReject(message.getMsgSeqNum(), SessionRejectReasonValues.RequiredTagMissing, text); }
/** * Create a message container. * * @return a message container */ public FIXMessage create() { return new FIXMessage(config.getMaxFieldCount(), config.getFieldCapacity()); }