kan
kan

Reputation: 28951

FIX repeating groups to reuse same tags

Does FIX protocol allow to reuse same tag in a message and in repeating groups? I.e. could I have something like that

        <message name='Quote' msgtype='S' msgcat='app'>
            <field name='Price' required='Y'/><!-- i.e. total price for the whole quote-->
    ...
            <group name='NumLegs' required='Y'>
                <field name='Price' required='Y'/><!-- i.e. leg price -->
    ...
                <group name='NumLegDetails' required='Y'>
                    <field name='Price' required='Y'/><!-- i.e. leg component price -->
    ...
                </group>
    ...
            </group>
        </message>

Upvotes: 2

Views: 2194

Answers (3)

Christoph John
Christoph John

Reputation: 3283

TL;DR

It is not allowed in the tag-value encoding.
(but in FIXML it is)

Some explanations

My initial misunderstanding came from this statement in the FIX tag-value specification: see here, search for "Field presence"

A tag (field) must appear at most once in a message, except when the tag appears within a repeating group.

But as I learned this refers to the wire format of the message, not the definition of the message.

Whereas the FIX5.0SP2 spec Volume 1 refers to the definition of the message and states:

A tag number (field) should only appear in a message once. If it appears more than once in the message it should be considered an error with the specification document.

In the meantime I even found it mentioned in FIXimate when looking at the NestedParties component (emphasis mine): (link to NestedParties component in FIXimate)

The NestedParties component block is identical to the Parties Block. It is used in other component blocks and repeating groups when nesting will take place resulting in multiple occurrences of the Parties block within a single FIX message.. Use of NestedParties under these conditions avoids multiple references to the Parties block within the same message which is not allowed in FIX tag/value syntax.

BTW, there are also components NestedParties2, NestedParties3, NestedParties4 to work around this.

Information from FIX Trading Community Forum

The thread can be accessed here, but as far as I know you can only access it if you are a FIX TC member: FIX TC forum

The FIX expert Hanno Klein gave the following information:

The quote from the refactored online spec refers to the wire format of any instance of a message encoded in tagvalue syntax. It means that inside the wire format of a single repeating group a tag (field) may appear more than once.

FIXML does not have this restriction:

The restriction is actually limited to the tagvalue encoding. For example, the parties component is “Pty” for all instances in FIXML, the XML syntax/encoding of FIX. This is due to the fact that the XML syntax has an unambiguous structure with a distinct path to every occurrence of a component or field. The XML names only need to be unique within the same element.

Tag-value does:

For tagvalue, a parser needs to know when a repeating group starts and ends. The NoXXX field marks the starting point and a field that is not part of the group marks the ending point. There are no explicit delimiters for repeating groups in tagvalue and components (non-repeating) are not visible in the wire format at all. Technically, you are probably right that a Price tag could exist in two distinct repeating groups without causing a parser issue but I do not see the benefit to allow this exception to the rule. You cannot allow it for two adjacent levels, e.g. root + nesting level 1 or nesting level x + nesting level y.


This part from original answer still applies

On another note, when defining your own repeating groups please use the notation NoXXX for repeating groups since that is the official recommendation. see here, search for "NumInGroup field"

It is recommended that NumInGroup fields be named NoXXX, e.g. NoContraBrokers(382).

However, following your example with 44/Price you would normally see 566/LegPrice used as the price for an individual leg since the two are used differently. The former is the price used for the execution of an order, the latter is used when defining a leg of a strategy.

So in short, when defining your message structure and repeating groups you should really think about if the meaning of the tag is the same for all occurrences of the tag in the message and if it really makes sense to use the very same tag in the body and in repeating groups. Clarity should be first priority.


incorrect (strike through) part of original answer

At first I thought that this could not be allowed but mainly because I have never seen it appear somewhere in a real message. But actually I could not find a reason why it should not be allowed. The specification only says: see here, search for "Field presence"

A tag (field) must appear at most once in a message, except when the tag appears within a repeating group.

A tag (field) must appear at most once per repeating group instance.

Upvotes: 4

Ciaran McHale
Ciaran McHale

Reputation: 2234

No, this is not allowed. I suggest you get a large data dictionary from http://www.quickfixengine.org, save it to your computer in XML format, and then execute a command like the following:

grep Price FIX.xml | grep number

Doing that will show you the definitions of all the Price-related fields. If you search for each of those field names within messages/components, you will see that each one is used in a different place. The overall result is that each field is listed only once in a message.

Upvotes: 1

user1717259
user1717259

Reputation: 2863

You can't re-use a repeating group tag outside a repeating group.

The declaration of a tag as a repeating group tag puts constraints on it, such as its order within a group and how one occurrence is treated differently to a subsequent occurrence. Non-repeating group tags have no such constraint.

Upvotes: 0

Related Questions