Documentation for QuickFIX/C++ (with Python and Ruby)

Working With Messages

Repeating Groups

QuickFIX has the ability to send messages containing repeating groups and even recursive repeating groups. All repeating groups begin with a field that indicates how many repeating groups are in a set. A group can be created by referencing a class named after this field scoped within the parent message or group.

Creating Messages With Repeating Groups

When a message is created the required field declaring the number of repeating groups is set to zero. QuickFIX will automatically increment field for you as you add groups.

C++
// create a market data message
FIX42::MarketDataSnapshotFullRefresh message(FIX::Symbol("QF"));

// repeating group in the form of MessageName::NoField
FIX42::MarketDataSnapshotFullRefresh::NoMDEntries group;
group.set(FIX::MDEntryType('0'));
group.set(FIX::MDEntryPx(12.32));
group.set(FIX::MDEntrySize(100));
group.set(FIX::OrderID("ORDERID"));
message.addGroup(group);

// no need to create a new group class if we are reusing the fields
group.set(FIX::MDEntryType('1'));
group.set(FIX::MDEntryPx(12.32));
group.set(FIX::MDEntrySize(100));
group.set(FIX::OrderID("ORDERID"));
message.addGroup(group);
Python
import quickfix
import quickfix42

message = quickfix42.MarketDataSnapshotFullRefresh()
group = quickfix42.MarketDataSnapshotFullRefresh().NoMDEntries()

group.setField(quickfix.MDEntryType('0'))
group.setField(quickfix.MDEntryPx(12.32))
group.setField(quickfix.MDEntrySize(100))
group.setField(quickfix.OrderID("ORDERID"))
message.addGroup( group )

group.setField(quickfix.MDEntryType('1'))
group.setField(quickfix.MDEntryPx(12.32))
group.setField(quickfix.MDEntrySize(100))
group.setField(quickfix.OrderID("ORDERID"))
message.addGroup( group )
Ruby
require 'quickfix_ruby'
require 'quickfix42'

message = Quickfix42::MarketDataSnapshotFullRefresh.new()
group = Quickfix42::MarketDataSnapshotFullRefresh::NoMDEntries.new();

group.setField(Quickfix::MDEntryType.new('0'))
group.setField(Quickfix::MDEntryPx.new(12.32))
group.setField(Quickfix::MDEntrySize.new(100))
group.setField(Quickfix::OrderID.new("ORDERID"))
message.addGroup(group)

group.setField(Quickfix::MDEntryType.new('1'))
group.setField(Quickfix::MDEntryPx.new(12.32))
group.setField(Quickfix::MDEntrySize.new(100))
group.setField(Quickfix::OrderID.new("ORDERID"))
message.addGroup(group)

Reading Messages With Repeating Groups

To pull a group out of a message you need to supply the group object you wish to pull out. You should first inspect the number of entries field (which the group is named after) to get the total number of groups. The message that was created above is now parsed in this example.

C++
// should be 2
FIX::NoMDEntries noMDEntries;
message.get(noMDEntries);

FIX42::MarketDataSnapshotFullRefresh::NoMDEntries group;
FIX::MDEntryType MDEntryType;
FIX::MDEntryPx MDEntryPx;
FIX::MDEntrySize MDEntrySize;
FIX::OrderID orderID;

message.getGroup(1, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);

message.getGroup(2, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);
Python
import quickfix
import quickfix42

noMDEntries = quickfix.NoMDEntries()
message.getField(noMDEntries)

group = quickfix42.MarketDataSnapshotFullRefresh.NoMDEntries()
MDEntryType = quickfix.MDEntryType()
MDEntryPx = quickfix.MDEntryPx()
MDEntrySize = quickfix.MDEntrySize()
orderID = quickfix.OrderID();

message.getGroup(1, group);
group.getField(MDEntryType);
group.getField(MDEntryPx);
group.getField(MDEntrySize);
group.getField(orderID);

message.getGroup(2, group);
group.getField(MDEntryType);
group.getField(MDEntryPx);
group.getField(MDEntrySize);
group.getField(orderID);
Python
require 'quickfix_ruby'
require 'quickfix42'

noMDEntries = Quickfix::NoMDEntries.new()
message.getField(noMDEntries)

group = Quickfix42::MarketDataSnapshotFullRefresh.NoMDEntries.new()
MDEntryType = Quickfix::MDEntryType.new()
MDEntryPx = Quickfix::MDEntryPx.new()
MDEntrySize = Quickfix::MDEntrySize.new()
orderID = Quickfix::OrderID.new();

message.getGroup(1, group);
group.getField(MDEntryType);
group.getField(MDEntryPx);
group.getField(MDEntrySize);
group.getField(orderID);

message.getGroup(2, group);
group.getField(MDEntryType);
group.getField(MDEntryPx);
group.getField(MDEntrySize);
group.getField(orderID);