![]() |
||||||||||||||||||||||||||||||||||||||||||||
FIX Parser |
||||||||||||||||||||||||||||||||||||||||||||
The FIX Parser transforms a raw message stream (bytes or string) into a FixMessage data structure which is suitable for querying the required information from the message. An object of the FixParser class does not need a FIX Data Dictionary for parsing simple messages. However, a FIX Data Dictionary is essential for parsing:
FF.FIX Engine also allows to create FixParserHint objects which:
|
||||||||||||||||||||||||||||||||||||||||||||
The FixParser class in the FF.Fix.Core.Message namespace offers fast and powerful parsing of a FIX Message stream resulting into a FixMessage object. The FixParser object can parse simple FIX Messages. However, it requires more inputs like FixDataDictionary and FixParserHint objects to deal with complexities like:
For example, the code for parsing a simple FIX Message string is: using FF.Fix.Core; //Specify the Raw Message string //Parse the Raw Message string by creating a FixParser object. //If a FixParser object gets created without parsing error, the FIX Message is valid. //Create a FixMessage object from the FixParser object for further processing. The FixParser constructor in the above example represents a default FixParser object constructor. It takes only the Raw Message string (rawFIXMessage) as input. The FixParser object created using the default constructor:
The FixParser object throws an error on violation of any of the above conditions. |
||||||||||||||||||||||||||||||||||||||||||||
For parsing complex messages, a constructor for FixParser objects should include a FIX Data Dictionary as inputs. Such constructor is given below: public FixParser identifierName = new FixParser(string originalRawFixMessage, FixDataDictionary fixDataDictionary); For example: /* Initially, create a new fixDataDictionary object using the required Data Dictionary file in XML format. */ //Access the original Raw FIX Message string. //Create a FixParser object from the message string and the fixDataDictionary object. //Get a FixMessage object from the FixParser object for further message processing. |
||||||||||||||||||||||||||||||||||||||||||||
The FixParserHint class in the FF.Fix.Core.Message namespace includes useful hints and information about Repeating Groups fields, Data type fields and custom Header fields. You can also override certain default validations through these objects, as required. Different constructors for FixParserHint objects are:
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
To parse a FIX Message stream having a Repeating Group, you require to provide an appropriate FixParserHint object containing the details about the Repeating Group field. For example: using FF.Fix.Core; /* In the following message string, Tag 268 is the Repeating Group (NumInGroup type) field. Two groups of fields (tag numbers 79, 69, 5, 70 and 71) would repeat as 268=2. */ /*Create the repeatingGroupFieldInfo object, which contains the information that: /* Create a msgRepeatingGroupFieldInfo object that shall contain information about the Repeating Group fields. */ /* Specify that the msgRepeatingGroupFieldInfo object shall contain information about the Repeating Group fields under Tag 268 in message type X. The AddMsgRepeatingGroupInfo method enables you to add information on Repeating Group fields across several message types into the same MsgRepeatingGroupFieldInfo object. */ /*Create a FixParserHint object for the Repeating Group fields. As the hint is not for Header or Data type fields, first two arguments are null. */ /* Create a FixParser object for parsing the Raw Message string. No Data Dictionary is specified. Hence the second argument is null. */ //Obtain a FixMessage object from the parsed message |
||||||||||||||||||||||||||||||||||||||||||||
To parse a FIX Message stream having Data type fields, you have to provide an appropriate FixParserHint object containing the details about the Data type fields. For example: A FIX Message contains the Body field RawData (tag 96). It is a Data type field with value Hello|World. The two words Hello and World are separated by a <SOH> character, shown by '|'. To parse this message successfully, the code would be as follows: using FF.Fix.Core; /*Create the msgDataTypeFieldInfo object, which contains the information that tag 96 is a Data type field in the message type A. */ /*Create a FIX parser hint for Data type fields. Note that the null value for the headerFields array indicates that there are no declarations for the same. Further, as there are no Repeating Groups, the third argument related to the MsgRepeatingGroupFieldInfo field parameter is also set to null. */ /*Create a new FixParser object. The null value for the second argument is related to Data Dictionary (not used here). */ //Create a FixMessage object from the parsed message. |
||||||||||||||||||||||||||||||||||||||||||||
If a FIX Message stream contains a binary or encoded data, the FixParser object takes a stream of byte data for successful parsing. See the following steps for verification:
The code for these steps is: using FF.Fix.Core; //Step 1: //Define rawFixMessage and create fixMessage1 structure from it. //Create a FixParser object based on rawFixMessage string. //Obtain a FixMessage object based on rawFixMessage from the FixParser object. //Step 2: //Insert tag 89 with the value “FFFIX” in an encoded form into the fixMessage1 structure. //Generate MD5 hash for FFFIX (Encoding). //Add binary information to the Signature field of the Trailer //Insert tag 91 with the value “My Secure Data” in an encoded form into fixMessage1. //Encoding the SecureData field. //Adding encoded information to the SecureData field in the Header part of fixMessage1. //Insert tag 96 with value “Body Raw Data Field” in an encoded form into fixMessage1. //Encoding the RawData field //Adding binary information to the Raw Data field in the Body part of fixMessage1. /Step 3: //Obtain the binary data bFixMessage1 from the modified fixMessage1 object. //Step 4: //Parse the byte array bFixMessage1 using a parser hint for Data type fields in the body. /*Specify that tag 96 is a Data type field from message type D and add this information into the msgDataTypeFieldInfo object. */ //Create a FIX parser hint for Data type fields. /*Create a new FixParser object. The null value for the second argument is related to the Data Dictionary (not used here). */ //Obtain the fixMessage2 object from the parsed binary message bFixMessage1. //Step 5: //Obtain a binary FIX Message with the name bFixMessage2 from the fixMessage2 structure. //step 6: //If bFixMessage1 = bFixMessage2, the parsing of encoded fields is successful. //Compare the binary messages bFixMessage1 and bFixMessage2. The identifier result returns the TRUE value. It means bFixMessage1 = bFixMessage2. This confirms the successful parsing of encoded fields. |
||||||||||||||||||||||||||||||||||||||||||||