Skip to content

ParseMessage messes up order of repeating group tags #568

@varunbpatil

Description

@varunbpatil

Steps to reproduce:

  1. Create a NOS message with a party ID repeating group.
  2. Convert it into bytes by calling msgBytes := nos.ToMessage().Bytes().
  3. Parse the bytes back into a quickfix message using qfMsg := quickfix.ParseMessage(msgBytes).
  4. Print the bytes from the parsed quickfix message using qfMsg.Bytes(). This should be equal to msgBytes which it is because qfMsg.Bytes() simply returns the rawMessage field.
  5. Now call qfMsg.Build() - I've made the build() method public to show the bug that happens when I actually try to send qfMsg to the counterparty.
  6. You will see that the order of tags in the party ID repeating group as a result of calling qfMsg.Build() is wrong.

Here is the code to reproduce the above issue (assuming you point to a quickfix code which has the build() method made public).

package main

import (
	"bytes"
	"fmt"
	"log"
	"time"

	"github.com/quickfixgo/enum"
	"github.com/quickfixgo/field"
	fix44nos "github.com/quickfixgo/fix44/newordersingle"
	"github.com/quickfixgo/quickfix"
	_ "github.com/quickfixgo/quickfix"
)

func main() {
	nos := fix44nos.New(
		field.NewClOrdID("1234"),
		field.NewSide(enum.Side_BUY),
		field.NewTransactTime(time.Now()),
		field.NewOrdType(enum.OrdType_LIMIT),
	)
	partyIDsgrp := fix44nos.NewNoPartyIDsRepeatingGroup()
	partyIDs := partyIDsgrp.Add()
	partyIDs.SetPartyID("party-in-da-house")
	partyIDs.SetPartyRole(enum.PartyRole_CLIENT_ID)
	nos.SetNoPartyIDs(partyIDsgrp)

	qfMsg := quickfix.NewMessage()
	if err := quickfix.ParseMessage(qfMsg, bytes.NewBuffer(nos.ToMessage().Bytes())); err != nil {
		log.Fatal(err)
	}

	// These two should be equal, but they're not. I've made qfMsg.Build() public for this example,
	// to show what message is being sent to the counterparty. The second print shows messed up
	// order of the party ID repeating group.
	fmt.Println(string(qfMsg.Bytes()))
	fmt.Println(string(qfMsg.Build()))
}

Here is the output of running the above code.

8=FIX.4.49=8235=D11=123440=254=160=20230622-08:23:27.847453=1448=party-in-da-house452=310=075
8=FIX.4.49=8235=D11=123440=254=160=20230622-08:23:27.847448=party-in-da-house452=3453=110=075

You will see that in the second print statement the party ID repeating group tags are (448, 452, 453), but it should have been (453, 458, 452).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions