OnixS C++ FIX Engine  3.25.0
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 tag-value format:

fix-protocol-message.gif

Message class

OnixS C++ FIX Engine exposes OnixS::FIX::Message class to encapsulate all services related with 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 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 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

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

Several overloads of the OnixS::FIX::Message::toString method are available to build tag-value presentation of a message instance. These overloads also simplify debugging and monitoring.

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;
}