OnixS C++ FIX Engine  4.10.1
API Documentation
FIX Message

Inner Contents

 Manipulating FIX Message Fields
 
 FIX Repeating Groups
 

Detailed Description

In general, FIX message represents a sequence of the 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 the FIX message in the tag-value format:

fix-protocol-message.gif

Message class

OnixS C++ FIX Engine exposes OnixS::FIX::Message class to encapsulate all services related to handling FIX messages.

Constructing Blank FIX Message

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

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 a 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

The OnixS::FIX::Message constructor is available to construct a message instance from its raw (tag-value) representation.

The OnixS::FIX::Message::toRaw method can be used to build a FIX-compliant tag-value presentation of the message. The output OnixS::FIX::RawMessage object contains the serialized FIX message in the same representation as it will be sent to the wire.

Pretty Print Methods

Several overloads of the OnixS::FIX::Message::toString method are available to build the pretty print tag-value presentation of a message instance. The delimiter parameter is used as a field delimiter. The flags parameter affects the resulting representation of the message. It can include field tag numbers, field names, and value descriptions. These overloads also simplify debugging and monitoring. Also, there is an ability to build the XML and JSON presentation of a message. The OnixS::FIX::Message::toXml and OnixS::FIX::Message::toJson methods can be used for this purpose.

Validating FIX 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 OnixS::FIX::Message::validate method must be used. This process is called "message validation" in the C++ FIX Engine terminology.

Example

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

using namespace OnixS::FIX;
using namespace OnixS::FIX::FIX42;
// Constructs blank "New Order - Single" message.
{
Message order(Values::MsgType::Order_Single, ProtocolVersion::FIX_42);
// Updates BodyLength (9) and CheckSum (10) fields with actual values.
order.validate();
std::cout << "Order " << order.toString() << std::endl;
}
// Reconstructs message from its raw presentation.
{
std::string rawOrder =
"8=FIX.4.0\0019=86\00135=D\00149=0\00156=0\00134=1\00152=99990909-17:17:17\001"
"11=90001008\00121=1\00155=IBM\00154=1\00138=10\00140=1\00159=0\00110=191\001";
Message order;
Message::parse(rawOrder.c_str(), rawOrder.length(), order);
order.validate();
std::cout << "Default text representation: " << order.toString() << std::endl;
std::cout << "Human-readable presentation: " << order.toString(' ') << std::endl;
std::cout << "Expanded presentation: " << order.toString('\001', MessageStringingFlag::IncludeFieldName | MessageStringingFlag::IncludeFieldTagNumber) << std::endl;
std::cout << "XML presentation: " << order.toXml() << std::endl;
std::cout << "JSON presentation: " << order.toJson() << std::endl;
}

Associating User Data

The OnixS::FIX::Message::userData() method can attach a user data pointer to the message object. This way can be used to associate some data with the given message object or pass user data with a message object through sending or receiving call stack. The user data is available in OnixS::FIX::ISessionListener, and OnixS::FIX::ISessionStorage callbacks are called for this particular message object.

Note
The message object does not manage the lifetime of user data. This is the responsibility of the user's code.