Getting fields from quickfix message
Asked Answered
D

3

5

I am using quickfix with python. Looking at the doc page here tells us how to get fields. Say a message = fix.message (with quickfix as fix) comes in from the counterparty. I can get the 35 (MsgType) field by calling

message.getHeader().getField(fix.MsgType())

which returns, for example, 35=X.

My question is: is there any method which just returns X? Or do I have to slice everything (like 35=X[3:], which returns X) and know the length of all the strings therefore?

Demonetize answered 12/10, 2015 at 20:48 Comment(0)
D
4

The answer is to get the field by first calling message.getHeader().getField(fix.MsgType()) then get the value by calling fix.MsgType().getValue().

Demonetize answered 13/10, 2015 at 20:21 Comment(1)
I couldn't get this to work . . . I ended up doing something like: message.getHeader().getField(fix.MsgType().getField())Jovian
K
5

I use a little util function

def get_field_value(self, fobj, msg):
    if msg.isSetField(fobj.getField()):
        msg.getField(fobj)
        return fobj.getValue()
    else:
        return None

that I call like this

clordid = get_field_value(fix.ClOrdID(), message)

for header fields, would look like this

def get_header_field_value(self, fobj, msg):
    if msg.getHeader().isSetField(fobj.getField()):
        msg.getHeader().getField(fobj)
        return fobj.getValue()
    else:
        return None
Knightly answered 20/9, 2016 at 20:29 Comment(0)
D
4

The answer is to get the field by first calling message.getHeader().getField(fix.MsgType()) then get the value by calling fix.MsgType().getValue().

Demonetize answered 13/10, 2015 at 20:21 Comment(1)
I couldn't get this to work . . . I ended up doing something like: message.getHeader().getField(fix.MsgType().getField())Jovian
C
0

Yes if you use the strongly typed approach, ie:

m.getHeader().getField(new MsgType());
Carlita answered 13/10, 2015 at 12:35 Comment(6)
Forgive my ignorance, but what is new MsgType() ?Demonetize
It's the "field name" for tag 35. See fixtradingcommunity.org/FIXimate/FIXimate3.0/en/FIX.5.0SP2/… so if you want any "field name" (which is basically a QF type) then go new FieldName() and QF should sort it out for you. For example: m.getHeader().getField(new SenderCompID()).getValue(); or m.get(new SettlDate());Carlita
m.getHeader().getField(new FieldName()) where FieldName is the field name you want the data for... You get qf types back so you can then go getValue() to get string values for most qf types.Carlita
I haven't tried this in PYTHON but presumably it's like QFJCarlita
Ah, I see. Well this doesn't work in Python! If new FieldName() in Java initiates a new class, this is basically what fix.FieldName() is doing in Python. Which leads back to my original questionDemonetize
In Java the code m.getHeader().getField(new MsgType()); returns X like you ask for...Carlita

© 2022 - 2024 — McMap. All rights reserved.