QuickFIX/J User Manual

User Defined Fields

FIX allows for users to define their own fields that do not belong to the spec. How can QuickFIX be used to set and get user defined fields? Well one answer would be to use the non-type safe set and get fields like so:

message.setField(new StringField(6123, "value"));
StringField field = message.getField(new StringField(6123));

But there is a better way. Instead of using this non type safe method, why not bring your own user defined fields into the type system? QuickFIX provides you with a set of macros to do just that. Now you can define your user defined fields in a separate file like this.

// MyStringField.java

import quickfix.StringField;

public class MyStringField extends StringField
  public MyStringField() { super(6123); }
  public MyStringField(String data) { super(6123, data); }

// MyPriceField.java

import quickfix.DoubleField;

public class MyPriceField extends DoubleField
  public MyPriceField() { super(8756); }
  public MyPriceField(double data) { super(8756, data); }

Now, elsewhere in your application, you can write code like this:

MyStringField stringField = new MyStringField("string");
MyPriceField priceField = new MyPriceField(14.54);