Generating FIX Dictionaries For FAST Coding
To initialize Decoder or Encoder two arguments are required: the FAST Template and the FIX dictionary.
The FAST template describes rules that are applied to binary data.
The FIX Dictionary describes the structures of FIX messages.
A FIX message consists of fields, and each field has the literal ("name"
) and numeric ("id"
or "tag"
) attributes.
- A FIX dictionary always defines both attributes:
tag
andname
. For example:<Field name="timestamp" tag="5004">
. - A FAST template should define at least one of them:
id
orname
. For example:<uInt32 name="timestamp" /> or <uInt32 id="5004" />
.
So an attribute omitted in the FAST-template could be retrieved from the FIX dictionary.
Note
Each name must be mapped to a unique number and vice versa. That's why it is possible to retrieve a name by the numeric id and vice versa.
Generation of FIX dictionary allows using only the FAST template. In this case, the FIX dictionary is built on the base of the given FAST template and the standard FIX dictionary (so-called base dictionary).
This approach significantly simplifies the usage of FAST decoders and encoders.
For example:
const bool decodeEachMessageIndependently = true;
// Create the decoder using FIX 4.4 as a base dictionary:
IMessageInfoDictionary generatedDictionary = DictionaryBuilder.BuildDictionary(ProtocolVersion.Fix44.ToDictionary(), fastTemplateStream);
// Pass the generated dictionary to the FAST decoder:
var decoder = new Decoder(fastTemplateStream, generatedDictionary, decodeEachMessageIndependently);
Message fixMessage = decoder.Decode(fastStreamChunk);
// Access the dictionary:
IMessageInfoDictionary activeDictionary = decoder.FixDictionary;
Preparing FAST template For FIX Dictionary Generation
The FAST template should satisfy the following requirements:
- Each field definition should contain both attributes:
"id"
and"name"
. - If a field definition is present several times, then it should either always be a simple field or always be a sequence.
Example of a correct FAST template:
<?xml version="1.0" encoding="UTF-8" ?>
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
<template id="100" name="Msg1">
<int32 name="Price" id="5200"><copy/></int32>
<int32 name="Amount" id="5201"/>
</template>
<template id="105" name="Msg2">
<decimal name="Price" id="5200"><default/></decimal>
<int32 name="Amount" id="5201"><delta/></int32>
</template>
</templates>
Example of a wrong FAST template:
<?xml version="1.0" encoding="UTF-8" ?>
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
<!-- Simple fields -->
<template id="100" name="Msg1">
<int32 name="NoProducts" id="5300"><copy/></int32>
<string name="Products" id="5301"><copy/></string>
</template>
<!-- Sequences -->
<template id="105" name="Msg2">
<sequence name="Products" id="5301">
<length name="NoProducts" id="5300"/>
</sequence>
</template>
</templates>