Python Quickfix - reading custom repeating groups
Asked Answered
S

1

2

This issue is almost identical to this which was not answered properly: Reading Repeating Groups in Custom Messages using Python Quickfix

python 2.7.15 on Windows, quickfix 1.15.1, FIX 4.2

I have a custom data dictionary from my trading platform provider which has custom fields and groups in the execution report. The full XML is available here: http://library.tradingtechnologies.com/tt-fix/System_Overview.html . In particular the group is defined as such:

        <group name='NoSecurityAltID' required='N'>
            <field name='SecurityAltID' required='N' />
            <field name='SecurityAltIDSource' required='N' />

I have specified the custom data dictionary and set UseDataDictionary=Y as specified elsewhere although I think this is the default anyway.

group= quickfix42.ExecutionReport.NoSecurityAltID()

returns an attribute error.

The strange thing is that NoContraBrokers is available as an attribute but that is not one of the groups in the custom dictionary but is in the standard 4.2 dictionary. I therefore thought that there was some error and that it was not parsing the custom dictionary but I have verified that it is.

I am new to quickfix (and python) so may have made an elementary error. But this has held me up for a long time now so would really appreciate some direction.

Update:

So I can only access standard FIX 4.2 groups by this method. I have now created a group:

group = quickfix.Group(454, 455)

where 454=NoSecurityAltID and 455=SecurityAltID.

Now I am struggling to read the string for the particular SecurityAltIDSource I want. This is the overview of the group:

Group overview

I want to read the 'Alias' and 'Name' but can only access the TagNumber for SecurityAltIDSource by

message.getGroup(1, group)
group.getField(456)

How can I access the strings for the fields I want?

Thanks

Update 2:

It was a simple error (although not a quick one to work out). I was able to access the field I wanted by:

group.getField(455)

I am concerned that using the field integers my not be as robust as another method. Is there a better way of doing this (short of recompiling the engine which would be beyond me)?

Slumgullion answered 22/8, 2018 at 9:40 Comment(0)
L
5

This may be a much delayed reply. I came across the same issue and was able to resolve it the following way.

Instead of using the field numbers, you can use the quickfix tags which will use the correct tags behind the scenes. I am using a sample tag 'NoAlloc' here but you can use any group you want.

import quickfix as qfix

# how many items are in the group
count = fixmsg.groupCount(qfix.NoAllocs().getTag())

# Getting the fields where 1 is the item in the list you want to retrieve
# from the repeating group. Index starts from 1 (not 0)
field_set = message.getGroupPtr(1, qfix.NoAllocs().getTag())

field_set.getField(qfix.AllocAccount())

NOTE: For custom groups, you will need to define your own fields and groups.

# Sample Field Declaration
class SampleField1(qfix.StringField):
    def __init__(self, data=None):
        if data is None:
            qfix.StringField.__init__(self, 456)
        else:
            qfix.StringField.__init__(self, 456, data)

# NoSampleGroup Field Declaration
class NoSampleGroup(qfix.IntField):
    def __init__(self, data=None):
        if data is None:
            qfix.StringField.__init__(self, 879)
        else:
            qfix.StringField.__init__(self, 879, data)

# Sample Group Declaration
class SampleGroup(qfix.Group):
    def __init__(self):
        order = qfix.IntArray(4)
        order[0] = 879     # This is the NoSamppleGroup field
        order[1] = 456     # This is the field in the repeating group
        order[2] = 0
        fix.Group.__init__(self, 879, 456, order)
Latchstring answered 29/8, 2019 at 8:48 Comment(2)
this is a much needed solution, thanks for posting. tl;dr: use msg.getGroupPtr instead of msg.getGroup to avoid weird quickfix issues.Carotenoid
Thanks very much for getGroupPtr. BTW, to read a message with custom groups and fields, it's only necessary to edit the data dictionary file, creating Python classes are not necessary.Rhachis

© 2022 - 2024 — McMap. All rights reserved.