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?

Wapiti
  • 1,851
  • 2
  • 20
  • 40

3 Answers3

3

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

Wapiti
  • 1,851
  • 2
  • 20
  • 40
  • 3
    I couldn't get this to work . . . I ended up doing something like: `message.getHeader().getField(fix.MsgType().getField())` – ernie Sep 13 '16 at 14:22
3

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
shaz
  • 2,317
  • 4
  • 27
  • 37
0

Yes if you use the strongly typed approach, ie:

m.getHeader().getField(new MsgType());
rupweb
  • 3,052
  • 1
  • 30
  • 57
  • Forgive my ignorance, but what is `new MsgType()` ? – Wapiti Oct 13 '15 at 12:49
  • 1
    It's the "field name" for tag 35. See http://www.fixtradingcommunity.org/FIXimate/FIXimate3.0/en/FIX.5.0SP2/tag35.html 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());` – rupweb Oct 13 '15 at 13:07
  • `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. – rupweb Oct 13 '15 at 13:12
  • I haven't tried this in PYTHON but presumably it's like QFJ – rupweb Oct 13 '15 at 13:14
  • 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 question – Wapiti Oct 13 '15 at 13:15
  • In Java the code `m.getHeader().getField(new MsgType());` returns X like you ask for... – rupweb Oct 13 '15 at 13:43