Modules | |
Manipulating Message Fields | |
FIX Repeating Groups |
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:
OnixS C++ FIX Engine exposes OnixS::FIX::Message class to encapsulate all services related with handling FIX messages.
To create blank FIX Message object OnixS::FIX::Message 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.
OnixS::FIX::Message constructor is available to construct message instance from its raw (tag-value) representation.
Several overloads of OnixS::FIX::Message::toString method are available to build tag-value presentation of a message instance. These overloads also simplify debugging and monitoring.
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 OnixS::FIX::Message::validate method must be used. In the OnixS C++ FIX Engine terminology this process is called message validation.
The following example demonstrates how messages can be created and parsed from the raw representation.
#include <OnixS/FIXEngine.h> using namespace OnixS::FIX; using namespace OnixS::FIX::FIX42; // Constructs blank "New Order - Single" message. { Message order(Values::MsgType::OrderSingle, FIX_42); // Updates BodyLength (9) and CheckSum (10) fields with actual values. order.updateCheckSum(); std::cout << "Order " << order.toString() << std::endl; } // Reconstructs message from its raw presentation. { std::string rawOrder = "8=FIX.4.0\0x019=86\0x0135=D\0x0149=0\0x0156=0\0x0134=1\0x0152=99990909-17:17:17\0x01" "11=90001008\0x0121=1\0x0155=IBM\0x0154=1\0x0138=10\0x0140=1\0x0159=0\0x0110=191\0x01"; Message order(rawOrder); order.validate(); std::cout << "Default stringizing: " << order.toString() << std::endl; std::cout << "Human-readable presentation: " << order.toString(' ') << std::endl; std::cout << "Expanded presentation: " << order.toString(Message::TAG_NAME | Message::TAG_NUMBER) << std::endl; }