In general, FIX message represents a sequence of fields whose values are associated with unique numbers (tags).

A common way of presenting FIX message is called the tag-value FIX message format. In such a format all fields are presented as tag=value pairs and are delimited by special <SOH> symbol.

The following image depicts the structure of FIX message in tag-value format:

FIX message structure

Message class

OnixS .NET FIX Engine exposes Message class to encapsulate all services related with handling FIX messages.

Constructing Blank Message

To create blank FIX Message object Message(String, ProtocolVersion) constructor must be used. It initializes message of specified type and FIX protocol version with no fields presented except couple of service fields like those which identifies type and version of FIX protocol to which constructed message belongs to.

Converting Message from and to Raw (Tag-Value) Format

Message(String) constructor is available to construct message instance from its raw (tag-value) representation.

Several overloads of ToString()()()() method are available to build tag-value presentation of a message instance. These overloads also simplify debugging and monitoring.

Validating Message

In addition to the presence of a particular field in the message of certain type, the FIX protocol also defines whether the presence of fields are strictly required in the message, whether they are required under certain conditions, or whether they are optional. To check for the presence of all required fields Validate()()()() method must be used. In OnixS .NET FIX Engine terminology this process is called message validation.

Example

The following example demonstrates how messages can be created and parsed from the raw representation.

CopyC#
// Creating a FIX Message object of type New Order, Single (MsgType = D).
Message order_1 = new Message(MsgType.Order_Single, ProtocolVersion.FIX40);

// Parsing a FIX message in the raw FIX format.
string rawFixMsg = "8=FIX.4.0\u00019=86\u000135=D\u000149=0\u000156=0\u000134=1\u000152=99990909-17:17:17\
  u000111=90001008\u000121=1\u000155=IBM\u000154=1\u000138=10\u000140=1\u000159=0\u000110=191\u0001";

Message order_2 = new Message(rawFixMsg);

order_2.Validate();

// Default presentation.
Console.WriteLine(order_2.ToString());

// Presentation delimited with spaces instead of SOH symbol.
Console.WriteLine(order_2.ToString(' '));

// More advanced presentation which allows to select which parts of fields information will be included.
Console.WriteLine(order_2.ToString(Message.StringFormat.TAG_NAME | Message.StringFormat.TAG_NUMBER, ' '));
CopyVB.NET
' Creating a FIX Message object of type New Order, Single (MsgType = D).
Dim order_1 As New Message(MsgType.Order_Single, FIXForge.NET.FIX.ProtocolVersion.FIX40)

' Parsing a FIX message in the raw FIX format
Dim rawFixMsg As String = "8=FIX.4.0" + ChrW(1) + "9=86" + ChrW(1) + "35=D" + ChrW(1) + "49=0" + ChrW(1) + "56=0" + ChrW(1) + "34=1" + ChrW(1)
  + "52=99990909-17:17:17" + ChrW(1) + "11=90001008" + ChrW(1) + "21=1" + ChrW(1) + "55=IBM" + ChrW(1) + "54=1" + ChrW(1) + "38=10" + ChrW(1)
  + "40=1" + ChrW(1) + "59=0" + ChrW(1) + "10=191" + ChrW(1)

Dim order_2 As New Message(rawFixMsg)

order_2.Validate()

' Default presentation.
Console.WriteLine(order_2.ToString())

' Presentation delimited with spaces instead of SOH symbol.
Console.WriteLine(order_2.ToString(" "))

' More advanced presentation which allows to select which parts of fields information will be included.
Console.WriteLine(order_2.ToString(Message.StringFormat.TAG_NAME Or Message.StringFormat.TAG_NUMBER, " "))