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 .NET FIX Engine supports such per session dialects in following manner.
Identifying Session-level Dialect in Dialects Description File
To focus the scope of a dialect definition from engine-wise to session level, the dialect definition must be enhanced with additional attributes id:
Example
<?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_5.xsd"> <!-- Attribute 'id' tells OnixS .NET 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>
| When the defined dialect description has non-empty id attribute, then the OnixS .NET FIX Engine will not use it for all sessions. Instead such a dialect can be used for specific sessions only. |
Referencing to Dialect in Session
In source code, an instance of 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 Dialect is created, the FIX session can be initialized. 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.
Example
using FIXForge.NET.FIX; Dialect customFIX = new Dialect("Custom FIX"); Session sessionWithCustomFIX = new Session("Sender", "Target", customFIX);
Imports FIXForge.NET.FIX Dim customFIX As New Dialect("Custom FIX") Dim sessionWithCustomFIX As New Session("Sender", "Target", customFIX)
Sending and Receiving Messages
To send messages of certain dialect, the instance of Dialect class must be supplied during Message construction.
An alternative way is to use CreateMessage(String) or ParseMessage(String) members of Dialect class. Both approaches are equivalent.
Example
using FIXForge.NET.FIX; Dialect customFIX = new Dialect("Custom FIX"); // Similar to how the Engine defines constants to certain FIX version, we // can define our namespace in which all custom fields and values will reside. // Therefore, assume that CustomFIX is an example of such namespace. Message orderOfCustomFIX = customFIX.CreateMessage(CustomFIX.MsgType.Order_Single); SetOrderFields(orderOfCustomFIX); orderOfCustomFIX.Validate(); sessionWithCustomFIX.Send(orderOfCustomFIX);
Imports FIXForge.NET.FIX Dim customFIX As New Dialect("Custom FIX") ' Similar to how the Engine defines constants to certain FIX version, we ' can define our namespace in which all custom fields and values will reside. ' Therefore, assume that CustomFIX is example of such namespace. Dim orderOfCustomFIX As Message = customFIX.CreateMessage(CustomFIX.MsgType.Order_Single) SetOrderFields(orderOfCustomFIX) orderOfCustomFIX.Validate() sessionWithCustomFIX.Send(orderOfCustomFIX)