Search code examples
fix-protocolquickfixj

How to create list order message in QuickFix/J


I'm trying to generate a "list orders" (forex orders) to be executed by my TargetCompID with QuickFix/J lib.

If I correctly understand the FIX message standard, my message must have the following fields (I've put my values in parenthesis):

Header part

  • 8 BeginString (FIX.4.4)
  • 9 BodyLength (will be computed and provided by quickfixj when sending)
  • 35 MsgType (E = NewOrderList)
  • 34 MsgSeqNum (will be computed and provided by quickfixj whend sending)
  • 49 SenderCompId (that's me)
  • 52 SendingTime (will be computed and provided by quickfixj when sending)
  • 56 TargetCompId (that's my counterparty which will execute my FX orders)

Then body part

  • 66 ListId (uniq id computed)
  • 68 ToNoOrders (count of my orders into list)
  • 73 NoOrders (same count value as I will generate a complete list of order at once)

Then repeat list of following fields (one list fields per order in my list):

  • 11 ClOrdId (my order id)
  • 67 ListSeqNo (index of the order into my list: from 1 to N; N = ToNoOrders = NoOrders)
  • ... several others fields as 15 (currency), 120 (SettlCurrency)

To do that I've done (in java / quickfixj):

Message message = new Message();
Header header = message.getHeader();
header.setField(new BeginString("FIX.4.4"));
header.setField(new MsgType("E"));
header.setField(new SenderCompID("it's me"));
header.setField(new TargetCompID("my counterparty"));
message.setField(new ListID(_fixListId));
message.setField(new TotNoOrders(_list.size()));
message.setField(new NoOrders(_list.size()));
int idx = 0;
for (Order order : _list) {
    message.setField(new ClOrdID(order.getId()));
    message.setField(new ListSeqNo(++idx));
    //message.setField(.... other fields to add to describe my order)
}

But doing this, in the callback function toApp of my quickfixj application ("This is a callback for application messages that you are being sent to a counterparty"), displaying the message in parameter (syso(message)) shows that only one order is inside my message, and it's the last oder I've put.

It seems they are some "group" we can create in QuickFixJ, and we can add several groups inside the same message. But there are a tons of kind of group, and I don't figure out what is the group appropriate for my "list order", if any? I see that there is a subclass of Message which is NewOrderList (it's my MsgType = E), but it's not a "group"; and it must be possible to create Message and provide MsgType directly...

Or maybe I don't understand correctly the FIX message standard and fields I have to provide?

Regards,

Alex


Solution

  • Instead of creating a message from scratch, you should be using the predefined messages in QuickFIX/J.

    In your case I would start looking at quickfix.fix44.NewOrderList.

    By using this class, a whole lot of fields will be filled in for you in the header and footer part of the message (BeginString, BodyLength, MsgType, CheckSum, ...). You then only need to concern yourself mostly with the main part (ie body) of the message.

    For the repeating group, there are helper classes available to set that information in the message. E.g. for NewOrderList.NoOrders:

    quickfix.fix44.NewOrderList fixMessage = new quickfix.fix44.NewOrderList (
        .... // check constructor for what parameters to pass
    );
    // ...
    quickfix.fix44.NewOrderList.NoOrders noOrders = new quickfix.fix44.NewOrderList.NoOrders();
    // ...
    fixMessage.addGroup( noOrders );