The dialect examples described above refer to engine-wide dialects. This means that specific dialects changes will affect each Engine session with only this FIX protocol dialect. Nevertheless, sometimes there is a need to use different FIX dialects in different FIX sessions within the same engine. The OnixS C++ FIX Engine supports such per session dialects in following manner.
To focus the scope of a dialect definition from engine-wise to session level, the dialect definition must be enhanced with additional attributes id
:
<?xml version="1.0" encoding="utf-8"?> <Dialect xmlns="http://onixs.biz/fix/dialects" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://onixs.biz/fix/dialects http://onixs.biz/fix/dialects/dialects-2_8.xsd"> <!-- Attribute 'id' tells OnixS C++ FIX Engine that dialect will be used in certain sessions only. It will not be used widely. --> <FIX version="4.0" id="Custom FIX"> <!-- Regular dialect description goes here. --> </FIX> </Dialect>
id
attribute, then the OnixS C++ FIX Engine will not use it for all sessions. Instead such a dialect can be used for specific sessions only.In source code, an instance of OnixS::FIX::Dialect class must be created. Its constructor accepts only one parameter which identifies the dialect you'd like to use for the session. Value of this parameter must be the same as in the XML description. Once an instance of OnixS::FIX::Dialect is created, the FIX session can be initialized. OnixS::FIX::Session initialization is performed in the usual way with the only one difference: instead of supplying the version of FIX protocol, the instance of appropriate Dialect class must be passed. After that the created session will operate using specified FIX dialect.
Dialect customFIX("Custom FIX"); Session sessionWithCustomFIX("Sender", "Target", customFIX, &defaultListener);
To send messages of certain dialect, the instance of OnixS::FIX:Dialect class must be supplied during Message construction.
Dialect customFIX("Custom FIX"); Message customOrder("D", customFIX); fillCustomFIXOrder(&customOrder); customOrder.validate();