Using DecoratorsFIX Antenna .NET Programmer's Guide

Decorators are helper classes that allow working with FixMessages using a convenient object model.

An example of code that uses Decorators can be found in Quick Samples

Advantage of Using Decorators

Below you can see 2 samples that create the same FixMessage without decorators and with them.

C#
FixMessage msg = FixMessage.Create(FixVersion.FIX44, "D"); 
// New Order - Single (MsgType = D)
msg.SetField(Tag.ClOrdID, "90001008"); 
msg.SetField(Tag.Side, "1");             
msg.SetField(Tag.TimeInForce, "0");
//...
Console.WriteLine("Msg: " + msg);
C#
//to use decorators, we need to use one of com.b2bits.FIXAntenna.Decorator.* namespaces
using com.b2bits.FIXAntenna.Decorator.FIX44;
//...
NewOrderSingle order = new NewOrderSingle(); 
// 
order.ClOrdID = "90001008"; 
order.Side = "1";             
order.TimeInForce = "0";
//...
Console.WriteLine("Msg: " + order.FlatMessage.ToString());

Decorators are convenient wrappers around raw FixMessages. By using Decorators developers gain strongly typed access to all available properties of a message, that increases development speed (you write less code to read/write to message properties) and reduces the number of validation errors (because each decorated message class contains only properties that are relevant to this class).

Thus, in the world of FIX messages, FixAntenna.NET Decorators are supposed to play the same role, as strongly-typed DataSets play in ADO.NET

We should also underline, that Decorators do not add any performance overhead and their performance is comparable with that of com.b2bits.FIXAntennaFixMessage class.

Using Decorators in Your Projects

To be able to use decorators, include a reference to Decorator_net2.0.dll assembly to your project. This assembly can be found in {FIX Antenna.NET install folder}\v{version}\lib\

Note Note

You need to include both FIXAntenna_net2.0.dll and Decorator_net2.0.dll in your projects to work with Fix messages.

Add the following namespace declaration com.b2bits.FIXAntenna.Decorator.FIX{fix_version}; to your code. For example, to create FIX messages compatible with FIX version 4.4 specifications (see FIX.4.4 ), use the following namespace:

//to use decorators, we need to use one of com.b2bits.FIXAntenna.Decorator.* namespaces
using com.b2bits.FIXAntenna.Decorator.FIX44;
Constructing New Messages

All classes that represent FIX messages in com.b2bits.FIXAntenna.Decorator.* namespaces are instantiated from one base class: StructuredMessage.

They have paramaterless constructors, like NewOrderSingle class from the example above.

One may also use the StructuredMessage.FromFlatMessage(FixMessage) method to create a decorator from an instance of the com.b2bits.FIXAntennaFixMessage class.

Also, the StructuredMessage.FlatMessage property can be used to convert a decorator back to an instance of plain com.b2bits.FIXAntennaFixMessage class. This conversion will be required to send an application-level message by using the SessionPut(FixMessage) method.

Working with Repeating Groups

Decorators also simplify work with repeating groups.

All properties that represent repeating groups are inherited from the StructuredGroup class.

This class works as a fixed size array, so you can modify properties of the elements in collection, but cannot add or remove items directly.

So, to increase or decrease the number of repeating groups, you should use the same approach that was described in Messages help topic (Repeating Groups chapter). I.e. when you want to add new groups, you need to set a corresponding field that represents the number of groups. Usually you should look for a property with name "No" + [Name of the repeating group]. For example, the property NoPartyIDsList controls the number of elements in PartyIDsList repeating group, see an example below.

NewOrderSingle order = new NewOrderSingle();

// set size of PartyId repeating group
order.NoPartyIDsList = 1;

// access to repeating group elements
order.PartyIDsList[0].PartyID = "INGS";
order.PartyIDsList[0].PartyIDSource = "C";

// set size of the nested repeating group
order.PartyIDsList[0].NoPartySubIDsList = 1;

// access inner group elements
order.PartyIDsList[0].PartySubIDsList[0].PartySubID = "0124";
order.PartyIDsList[0].PartySubIDsList[0].PartySubIDType = 17;

// resize repeating group
order.NoPartyIDsList = 2;
order.PartyIDsList[1].PartyID = "XXXX";
order.PartyIDsList[1].PartyIDSource = "C";

// destroy repeating group
order.RemoveField(Tag.NoPartyIDs);
See Also

Other Resources