How to validate FIX messages within the user code in FIX Antenna HFT

Overview

This article describes how to validate FIX messages in FIX Antenna HFT in case of FIX protocol violation.

How to validate FIX messages within the user code in FIX Antenna HFT

When the incoming FIX message violates FIX protocol there is a need to validate such message. If the message contains validation errors, an exception should be generated and a Reject message should be sent to the counterparty.

The Utils::Exception is a base class so the more specific exception from a parser is needed here.

Instead of Utils::Exception the ParserException is needed to obtain information for the Reject message.

The header file \include\fixantenna\engine\src\parser\src\ParserException.h for the ParserException class contains all the needed information, including the reject reason.

The following piece of code shows how to validate messages:

void validateLiteMsg( Engine::MsgPipeElem* poolElem )
{
	try
 	{
 		int size;
  		const char* ptr = elem->msg.toRaw(&size);
  		std::auto_ptr<Engine::FIXMessage> nonLiteMsg( Engine::FIXMsgProcessor::singleton()->parse(ptr, size, NULL, false, false ) ); //parse() can throw
  		// validate the message values
 		nonLiteMsg->checkFields();
 		//validate the message structure
 		Parser::Options opts; // set the opts as required
 		opts.verifyTagsValues = false; //already done 
 		nonLiteMsg->checkRequired(opts);
	}
	catch (Parser::ParserException const& e)
 	{
  		sendReject(elem->msg, e.refSeqNum(), e.refTagID(), e.refMsgType(), e.getRejReason(), e.what() );
	}
 	catch (std::exception const &e)
	{
  		logError(e.what());
 	}
}

FIX Antenna HFT Parser exceptions

Here is the list of Parser exceptions thrown by all public methods of Fix Antenna HFT:

 

ExceptionDescription
fixantenna/engine/src/parser/src/ParserException.h: class ParserException : public FixProtocolException Appears when something is wrong with the message format, e.g. the message format does not correspond to the protocol defines.
fixantenna/engine/src/parser/src/ParserException.h: class InvalidTagNumberException : public ParserExceptionThe tag number is invalid.
fixantenna/engine/src/parser/src/ParserException.h: class RequiredTagMissingException : public ParserExceptionThe required tag is missing.
fixantenna/engine/src/parser/src/ParserException.h: class TagNotDefinedForThisMessageTypeException : public ParserExceptionThe tag is not defined for this message type.
fixantenna/engine/src/parser/src/ParserException.h: class TagSpecifiedWithoutValueException : public ParserExceptionThe tag is specified without a value.
fixantenna/engine/src/parser/src/ParserException.h: class InvalidMsgTypeException : public ParserExceptionThe MsgType (35) is invalid.
fixantenna/engine/src/parser/src/ParserException.h: class TagAppearsMoreThanOnceException : public ParserExceptionThe tag is duplicated.
fixantenna/engine/src/parser/src/ParserException.h: class RepeatingGroupFieldsOutOfOrderException : public ParserExceptionRepeating group fields are out of order.
fixantenna/engine/src/parser/src/ParserException.h: class IncorrectNumInGroupCountForRepeatingGroupException : public ParserExceptionThe NumInGroup count for repeating group is incorrect.
fixantenna/engine/src/parser/src/ParserException.h: class IncorrectCheckSumException : public ParserExceptionThe CheckSum is incorrect.
fixantenna/engine/src/parser/src/ParserException.h: class IncorrectMessageLengthException : public ParserException

The message length is invalid.

fixantenna/engine/src/parser/src/ParserException.h: class FieldLengthExceededException : public ParserExceptionThe field length exceeds the maximum value.
fixantenna/engine/src/parser/src/ParserException.h: class TagParsingException : public ParserExceptionThe parsing of the field from the raw message is failed.
fixantenna/engine/src/parser/src/ParserException.h: class TagOutOfOrderException: public Parser::ParserExceptionThe tag is specified out of the required order.
fixantenna/engine/src/parser/src/ParserException.h: class RepeatingGroupIndexOutOfRangeException : public ParserExceptionThe repeating group index is out of the range.
fixantenna/engine/src/parser/src/ParserException.h: class RequiredBlockWithoutFields : public ParserExceptionThe required block doesn't contain any fields.
fixantenna/engine/src/parser/src/ParserException.h: class SenderTargetValidationError : public ParserExceptionThe Sender/Target field differs from the expected in the received message.