Reading Repeating Groups in Custom Messages using Python Quickfix
Asked Answered
M

2

3

I am trying to read from a FIX engine using Python and Quickfix, and have managed to get the engine to recognize custom messages by modifying the data dictionary used (with necessary message groups).

The problem I am now facing is reading repeating groups from the custom messages. The quickfix documentation shows the following:

import quickfix
import quickfix42

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

group = quickfix42.MarketDataSnapshotFillRefresh.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);

...which is fine for FIX messages. When i try and reference my custom message like so:

group = quickfix.CustomMessage.NoMDEntries()

...I get an attribute error.

Any ideas on how to read repeating groups in custom messages?

Edit 1:

i found a hack, but am certain there is a better way of doing this...

for i in range(int(message.getField(NoMDEntries):
    group = quickfix.Group(int(message.repeatingField), int(message.delimField))
    message.getGroup(i+1, group)
    print group.getField(MDEntryPx)
    #do something with repeating fields etc

...ideas anyone?

Multiplier answered 15/2, 2012 at 9:39 Comment(1)
Your edit is a solid solution to your question. The quickfix standards, like market data snapshot messages, internally invoke custom instances of quickfix.Group in a similar manner as you - just adhering to standard field entries for the repeater and delimiter. One tip is that the group entry only needs to be instantiated once, and can be done outside your looping! (for the group entry single instantiation pattern, see the pattern in quickfix documentation here: quickfixengine.org/quickfix/doc/html/python/…).Dangelo
K
1

Not sure about the Python stub you supplied, but I see maybe a problem.

group = quickfix42.MarketDataSnapshotFillRefresh.NoMDEntries()

Here you get the inner class object inside the MarketDataSnapshotFullRefresh(you probably have misspelt it MarketDataSnapshotFillRefresh) object.

group = quickfix.CustomMessage.NoMDEntries()

Here you probably get is the number(count) of repeating groups inside the repeating group, instead of the class object.

Quickfix provides the getGroup method to browse through the group members, so use it rather than doing it yourself.

Kyrstin answered 15/2, 2012 at 12:54 Comment(2)
Thanks for the pointer...however, I am unable to access the CustomMessage from the dictionary...any idea how can i reference fields and/or groups for custom messages?Multiplier
More details here: quickfixengine.org/quickfix/doc/html/repeating_groups.htmlLeonaleonanie
Y
0

please delete the below codes in your documents: message.getField(noMDEntries)

then it will work well to get the value that you want.

Yarkand answered 23/9, 2021 at 3:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.