private void setRejectReason(Message reject, int field, String reason, boolean includeFieldInReason) { boolean isRejectMessage; try { isRejectMessage = MsgType.REJECT.equals(reject.getHeader().getString(MsgType.FIELD)); } catch (final FieldNotFound e) { isRejectMessage = false; } if (isRejectMessage && sessionID.getBeginString().compareTo(FixVersions.BEGINSTRING_FIX42) >= 0) { reject.setInt(RefTagID.FIELD, field); reject.setString(Text.FIELD, reason); } else { reject.setString(Text.FIELD, reason + (includeFieldInReason ? " (" + field + ")" : "")); } }
private void generateHeartbeat(Message testRequest) throws FieldNotFound { final Message heartbeat = messageFactory.create(sessionID.getBeginString(), MsgType.HEARTBEAT); initializeHeader(heartbeat.getHeader()); if (testRequest.isSetField(TestReqID.FIELD)) { heartbeat.setString(TestReqID.FIELD, testRequest.getString(TestReqID.FIELD)); } if (enableLastMsgSeqNumProcessed) { heartbeat.getHeader().setInt(LastMsgSeqNumProcessed.FIELD, testRequest.getHeader().getInt(MsgSeqNum.FIELD)); } sendRaw(heartbeat, 0); }
private static Message createQuoteMessage(String reqId, Quote quote) { Message message = new Message(); message.getHeader().setField(QUOTE_MSG_TYPE); message.setField(new QuoteReqID(reqId)); message.setField(new DoubleField(MktBidPx.FIELD, quote.getBid(), 2)); message.setField(new DoubleField(MktOfferPx.FIELD, quote.getBid(), 2)); return message; }
static String getExecutionID(Message inMessage) { if (inMessage.isSetField(ExecID.FIELD)) { try { return inMessage.getString(ExecID.FIELD); } catch (FieldNotFound ignore) { } } return null; } static BigDecimal getLastQuantity(Message inMessage) {
static BigDecimal getLastPrice(Message inMessage) { if (inMessage.isSetField(LastPx.FIELD)) { try { return inMessage.getDecimal(LastPx.FIELD); } catch (FieldNotFound ignore) { } } return null; } static String getLastMarket(Message inMessage) {
private String getMessageToLog(final Message message) { return (message.toRawString() != null ? message.toRawString() : message.toString()); }
/** * Create a new cancel helper from the given inputs. * * @param inMsgType a <code>String</code> value * @param inOldMessage a <code>Message</code> value * @param inOnlyCopyRequiredFields a <code>boolean</code> value * @return a <code>Message</code> value * @throws FieldNotFound */ public Message newCancelHelper(String inMsgType, Message inOldMessage, boolean inOnlyCopyRequiredFields) throws FieldNotFound { Message cancelMessage = msgFactory.create(beginString, inMsgType); addApplicationVersion(cancelMessage); cancelMessage.setField(new OrigClOrdID(inOldMessage.getString(ClOrdID.FIELD))); fillFieldsFromExistingMessage(inOldMessage, inOnlyCopyRequiredFields, cancelMessage); if (inOldMessage.isSetField(OrderQty.FIELD)){ cancelMessage.setField(inOldMessage.getField(new OrderQty())); } addTransactionTimeIfNeeded(cancelMessage); addSendingTime(cancelMessage); return cancelMessage; }
final Header header = message.getHeader(); final String msgType = header.getString(MsgType.FIELD); if (sessionID.isFIXT()) { targetDefaultApplVerID.set(new ApplVerID(message .getString(DefaultApplVerID.FIELD))); if (message.isSetField(HeartBtInt.FIELD)) { if (message.getInt(HeartBtInt.FIELD) < 0) { throw new RejectLogon("HeartBtInt must not be negative"); if (message.isSetField(e.getField())) { if (rejectInvalidMessage) { throw e; getLog().onErrorEvent( "Warn: incoming message with incorrect field: " + message.getField(e.getField()) + ": " + getMessageToLog(message)); && message.isApp()) { generateBusinessReject(message, BusinessRejectReason.CONDITIONALLY_REQUIRED_FIELD_MISSING, e.field);
private void generateBusinessReject(Message message, int err, int field) throws FieldNotFound, IOException { final Message reject = messageFactory.create(sessionID.getBeginString(), MsgType.BUSINESS_MESSAGE_REJECT); final Header header = message.getHeader(); reject.reverseRoute(header); initializeHeader(reject.getHeader()); final String msgType = header.getString(MsgType.FIELD); final String msgSeqNum = header.getString(MsgSeqNum.FIELD); reject.setString(RefMsgType.FIELD, msgType); reject.setString(RefSeqNum.FIELD, msgSeqNum); reject.setInt(BusinessRejectReason.FIELD, err); state.incrNextTargetMsgSeqNum(); final String reason = BusinessRejectReasonText.getMessage(err); setRejectReason(reject, field, reason, field != 0); getLog().onErrorEvent( "Reject sent for message " + msgSeqNum + (reason != null ? (": " + reason) : "") + (field != 0 ? (": tag=" + field) : "")); sendRaw(reject, 0); }
/** * Tries to set MsgSeqNum and MsgType from a FIX string to a new Message. * These fields are referenced on the outgoing Reject message. * * @param messageString FIX message as String * @return New quickfix.Message with optionally set header fields MsgSeqNum * and MsgType. */ static Message getMinimalMessage(String messageString) { final Message tempMessage = new Message(); final String seqNum = getStringField(messageString, 34); if (seqNum != null) { tempMessage.getHeader().setString(34, seqNum); } final String msgType = getStringField(messageString, 35); if (msgType != null) { tempMessage.getHeader().setString(35, msgType); } return tempMessage; }
static void validate(Message message, DataDictionary sessionDataDictionary, DataDictionary applicationDataDictionary) throws IncorrectTagValue, FieldNotFound, IncorrectDataFormat { final boolean bodyOnly = sessionDataDictionary == null; if (isVersionSpecified(sessionDataDictionary) && !sessionDataDictionary.getVersion().equals( message.getHeader().getString(BeginString.FIELD)) && !message.getHeader().getString(BeginString.FIELD).equals("FIXT.1.1") && !sessionDataDictionary.getVersion().equals("FIX.5.0")) { throw new UnsupportedVersion("Message version '" + message.getHeader().getString(BeginString.FIELD) + "' does not match the data dictionary version '" + sessionDataDictionary.getVersion() + "'"); } if (!message.hasValidStructure() && message.getException() != null) { throw message.getException(); } final String msgType = message.getHeader().getString(MsgType.FIELD); if (isVersionSpecified(applicationDataDictionary)) { applicationDataDictionary.checkMsgType(msgType); applicationDataDictionary.checkHasRequired(message.getHeader(), message, message.getTrailer(), msgType, bodyOnly); } if (!bodyOnly) { sessionDataDictionary.iterate(message.getHeader(), HEADER_ID, sessionDataDictionary); sessionDataDictionary.iterate(message.getTrailer(), TRAILER_ID, sessionDataDictionary); } applicationDataDictionary.iterate(message, msgType, applicationDataDictionary); }
msgType=outgoingMessage.getHeader().getString(MsgType.FIELD); } catch (FieldNotFound ex) { Messages.FIX_OUTGOING_NO_MSGTYPE.error(LOGGER_NAME, ex); Iterator<Field<?>> fieldItr=existingMessage.iterator(); while (fieldItr.hasNext()) { Field<?> field = fieldItr.next(); && !outgoingMessage.isSetField(fieldInt) && dict.isMsgField(msgType, fieldInt)) { try { outgoingMessage.setField(existingMessage .getField(new StringField(fieldInt))); } catch (FieldNotFound e) {
private Object cloneTo(Message message) { message.initializeFrom(this); message.header.initializeFrom(getHeader()); message.trailer.initializeFrom(getTrailer()); return message; }
String nsURI = null; Message message = new Message(); SOAPBody soapBody = msgCtx.getEnvelope().getBody(); message.getHeader().setString(Integer.parseInt(tag), value); message.getTrailer().setString(Integer.parseInt(tag), value);
private boolean isGoodTime(Message message) throws FieldNotFound { if (!checkLatency) { return true; } final LocalDateTime sendingTime = message.getHeader().getUtcTimeStamp(SendingTime.FIELD); return Math.abs(SystemTime.currentTimeMillis() - sendingTime.toInstant(ZoneOffset.UTC).toEpochMilli()) / 1000 <= maxLatency; }
char ordStatus = inMessage.getField(new OrdStatus()).getValue(); switch(ordStatus) { case OrdStatus.REJECTED: case OrdStatus.EXPIRED: if (!inMessage.isSetField(LeavesQty.FIELD)) { inMessage.setField(new LeavesQty(0)); BigDecimal initial = inMessage.getDecimal(OrderQty.FIELD); BigDecimal cumQty = inMessage.getDecimal(CumQty.FIELD); inMessage.setField(new LeavesQty(initial.subtract(cumQty))); break; if(!inMessage.isSetField(quickfix.field.ExecType.FIELD)) { inMessage.setField(new ExecType(ordStatus));
private FieldMap getAppropriateMap(Integer fieldID, Message message) { FieldMap map; if (dataDictionary.isHeaderField(fieldID)) { map = message.getHeader(); } else if (dataDictionary.isTrailerField(fieldID)) { map = message.getTrailer(); } else { map = message; } return map; }
private void sendResendRequest(String beginString, int msgSeqNum, int beginSeqNo, int endSeqNo) { int lastEndSeqNoSent = resendRequestChunkSize == 0 ? endSeqNo : beginSeqNo + resendRequestChunkSize - 1; if (lastEndSeqNoSent > endSeqNo) { lastEndSeqNoSent = endSeqNo; } if (lastEndSeqNoSent == endSeqNo && !useClosedRangeForResend) { if (beginString.compareTo("FIX.4.2") >= 0) { endSeqNo = 0; } else if (beginString.compareTo("FIX.4.1") <= 0) { endSeqNo = 999999; } } else { endSeqNo = lastEndSeqNoSent; } final Message resendRequest = messageFactory.create(beginString, MsgType.RESEND_REQUEST); resendRequest.setInt(BeginSeqNo.FIELD, beginSeqNo); resendRequest.setInt(EndSeqNo.FIELD, endSeqNo); initializeHeader(resendRequest.getHeader()); sendRaw(resendRequest, 0); getLog().onEvent("Sent ResendRequest FROM: " + beginSeqNo + " TO: " + lastEndSeqNoSent); state.setResendRange(beginSeqNo, msgSeqNum - 1, resendRequestChunkSize == 0 ? 0 : lastEndSeqNoSent); }
/** * Create a new MessageWrapper instance. * * @param inMessage a <code>Message</code> value * @throws FieldNotFound if the message is invalid */ private MessageWrapper(Message inMessage) throws FieldNotFound { message = inMessage; msgType = message.getHeader().getString(quickfix.field.MsgType.FIELD); requestId = message.getString(quickfix.field.MDReqID.FIELD); } /**