分组(group) 是包含一个无序的字段的集合的命名类型。允许在一个循环组里出现重复的数据字段。
QuickFIX/N 实现了在FIX消息中创建和读取的组信息的功能。
1) 创建循环分组
创建一个循环分组很简单: 创建一个分组类的实例,向分组内添加字段,然后把它添加到消息中
var tcr = new QuickfiFix.FIX44.TradeCaptureReport();
var sidesGrp1 = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
sidesGrp1.Account = new Account("Silvio");
sidesGrp1.OrderID = new OrderID("09011900");
sidesGrp1.Side = new Side(Side.BUY);
var sidesGrp2 = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
sidesGrp2.Account = new Account("Sven");
sidesGrp2.OrderID = new OrderID("2000");
sidesGrp2.Side = new Side(Side.BUY);
tcr.AddGroup(sidesGrp1);
tcr.AddGroup(sidesGrp2);
分组可以嵌套,也就是分组内还可以创建子分组:
var tcr = new QuickFix.FIX44.TradeCaptureReport();
var sidesGrp = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
sidesGrp.Side = new Side(Side.BUY);
sidesGrp.Account = new Account("Piola");
sidesGrp.OrderID = new OrderID("09011900");
var partyIdsGrp = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup.NoPartyIDsGroup();
partyIdsGrp.PartyID = new PartyID("Nesta13");
sidesGrp.AddGroup(partyIdsGrp);
tcr.AddGroup(sidesGrp);
2) 读取分组的信息
QuickFIX/N提供组字段和组索引两种方式来支持从组内读取标签信息:
var sidesGrp1 = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
sidesGrp1 = tcr.GetGroup(1, Tags.NoSides);
var sidesGrp2 = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
sidesGrp2 = tcr.GetGroup(2, Tags.NoSides);
组索引从1开始。我们可以使用for语句来循环读取分组的字段值:
var noSidesGrp = new QuickFix.FIX44.TradeCaptureReport.NoSidesGroup();
for(int grpIndex = 1; grpIndex<= message.GetInt(Tags.NoSides); grpIndex = 1)
{
noSidesGrp = message.GetGroup(grpIndex, Tags.NoSides);
}