OnixS::FIX::Message class represents a generic model of any FIX message, in order to manipulate such a message, you need to check the message type and know what fields exist in this message, all of this is not safe and creates some development complexity, so to simplify the FIX message handling and make this more safe you can use strongly typed message classes instead of the generic Message class. Such typed message classes can be generated by the generator tool.
There are two modes in the typed messages generator.
In the first one, the messages are generated based on the FIX Dictionary file provided. This mode is enabled by specifying the dictionary argument.
In the second one, the generation performed based on the standard FIX Dictionary for the provided FIX versions, which must be specified. This mode is enabled by specifying the versions argument.
It is possible to provide the generator with a filter for messages to be dispatched as incoming ones. It reduces the generated code size and achieves performance benefits for message dispatching. To do so, message-types argument can be used. If no filter provided, all the messages are treated as incoming ones.
Below are the description for the Generator arguments:
| Argument | Required | Description |
|---|---|---|
| dictionary | Y | A path to the FIX dictionary file, the first mode |
| versions | Y | A comma-separated list of FIX versions, the second mode |
| out-name | N | A name to the files, where typed messages classes are saved |
| std | N | The C++ standard version (Cxx11, Cxx14, Cxx17, Cxx20, universal (use macros)) |
| message-types | N | A comma-separated list of messages to be dispatched as incoming |
| namespace | N | The root namespace for the generated code, OnixS::FIX by default |
| tags | N | Generate the namespace with the tag constants, see Tag Constants |
Example: --versions=FIX40,FIX50sp1 --out-dir=Generated --std=Cxx17 --message-types=D,8: generate messages based on standard FIX Dictionary for FIX versions 4.0 and 5.0 SP1, use C++17, put generated classes in files named Generated, treat messages with types D and 8 as incoming.
The typed messages generator is a .NET 9 application. This means that it requires installing the corresponding dotnet-sdk. For example, for Linux, please see the Install .NET on Linux page for details. To run the generator, one can use the following command:
It is very similar to the standard interface, but the listener object must be inherited from TypedMessageListener, instead of OnixS::FIX::ISessionListener.
It is very similar to the standard interface. The strongly-typed message object is created, and the fields are set with the corresponding setters.
To receive an incoming messages, it is necessary to override the corresponding method of TypedMessageListener class. The incoming messages are delivered via these callbacks.
The strongly-typed message getters provide a type specified in the FIX Dictionary during the generation; no type conversion is required.
For non-required fields, the getter's return a boolean value that indicates the field's presence, and the value itself is returned by reference.
If a message with an unexpected type is received, it is delivered to the user via TypedMessageListener::onUnrecognizedMessage callback.
Every group and its entry are exposed as a nested class of a correspondent owner (message or another group).
To add a new repeating group or modify the number of instances of the existing one, a method named after the group name must be used as in the following example. The method accepts a new number of repeating group entries as a parameter and returns an instance of a newly created or modified repeating group.
To allow traversing group entries, every typed group entry class is a descendant of OnixS::FIX::TypedGroup class, which contains correspondent methods: querying groups size, accessing the group's entries, etc. The index operator (or OnixS::FIX::TypedGroup::at member) returns an entry that allows fields access in the very same manner the message does. The indexing entry starts from zero.
The following example demonstrates how to traverse over the repeating group entries:
A group can also be traversed using an iterator:
A group can also be traversed using range-based for loop:
The tags argument adds a namespace with the tag constants to the generated header. It is laid out like the namespace of the same name in the standard dictionary headers such as FIX42.h:
The constants name the fields that the generated messages, the standard header and the standard trailer contain. Fields that the dictionary declares but no message uses are not generated, because no typed message exposes them.
The tag names repeat the field names of the dictionary, so they match the generated getters and setters. A dictionary that keeps an editorial note in the field name produces a constant that carries the note as well: the FIX 4.2 field Rule80A(aka OrderCapacity) for tag 47 becomes Tags::Rule80AAkaOrderCapacity, next to the rule80AAkaOrderCapacity() getter of the same header. Generation stops with an error when two different tags produce the same constant, which happens for field names that differ only in the characters dropped while building an identifier. The name Tag is reserved, because it is the type of the constants: neither a field nor the namespace may take it.
Tag constants make the generated header self-sufficient, so the standard dictionary header is no longer needed to name a tag. The generated classes add accessors for the message body only, so a standard header field is read from the underlying OnixS::FIX::Message by tag:
The Strongly Typed Messages are implemented as a very thin wrapper, which incurs almost no additional overhead. Moreover, because of the highly optimized message dispatching, there could be some performance benefits.