forwardSelecting FIX Version   Table of ContentManipulating Message Fieldsforward
FIX Message

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

A common way of presenting a 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 Framework FIX Engine exposes the Message class to encapsulate all services related to handling FIX messages.

Constructing Blank Message

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

Note Note

By reason of the internal design you cannot change the message type of the created message and perform the validation correctly, when a FIX message is created with the certain type then the particular message structure is associated with this message to perform validation and determine undefined fields, so you need to create a new message when you want to change the message type.

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 the ToString() method are available to build a 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 a 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, the Validate() method must be used. In OnixS .NET Framework FIX Engine terminology, this process is called message validation.

Message life cycle

Sometimes there is a need to use the message after it was sent to a session. As soon as the message was sent, the FixEngine will not use it later, so it can be disposed to help garbage collector, or used again; for example, it will be sent to other sessions.

C#
Message msg = new Message(MsgType.NewOrderSingle, ProtocolVersion.FIX44);
session.Send(msg);
msg.Dispose();
VB
Dim msg As New Message(MsgType.NewOrderSingle, FIXForge.NET.FIX.ProtocolVersion.FIX44)
session.Send(msg)
msg.Dispose()
Or
C#
Message msg = new Message(MsgType.NewOrderSingle, ProtocolVersion.FIX44);
foreach (Session session in sessions)
    session.Send(msg);
msg.Dispose();
VB
Dim msg As New Message(MsgType.NewOrderSingle, FIXForge.NET.FIX.ProtocolVersion.FIX44)
For Each session As Session In sessions
  session.Send(msg)
Next
msg.Dispose()

Please note that message object is not thread-safe, so it cannot be used in one thread while it is used in another. In this case, a foreach cycle with session.Send() cannot execute as parallel.

Example

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

C#
// Creating a FIX Message object of type New Order, Single (MsgType = D).
Message order_1 = new Message(MsgType.NewOrderSingle, ProtocolVersion.FIX44);

// 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, ' '));
VB
' Creating a FIX Message object of type New Order, Single (MsgType = D).
Dim order_1 As New Message(MsgType.NewOrderSingle, FIXForge.NET.FIX.ProtocolVersion.FIX44)

' 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, " "))
Content