• Programmer’s Guide
  • Api Documentation
  • FIX Prepared Message
Show / Hide Table of Contents
  • License Agreement
  • Release Notes
  • Backgrounder
    • About FIX
    • About FIX messages
    • About FIX sessions
    • About FIX 5.0
  • Installation And Uninstallation
    • Requirements & Compatibility
    • Supported Features
    • Samples descriptions
    • Uninstallation instructions
  • Quick Start
    • Session acceptor creation
    • Session initiator creation
    • Creating new order
    • Sending order
    • Processing incoming message
    • Closing session
    • Sample application
  • Basic Concepts
    • Main components
    • FixServer description
    • IFixServerListener description
    • IFixSessionListener description
    • IFixSession description
    • Repeating Groups description
    • Message validation
  • FIX Session Acceptor
    • Create
    • Connect
    • Reject
    • Reconnect
    • Disconnect
    • Release
    • Send message
  • FIX Session Initiator
    • Create
    • Establish connection
    • Reconnect
    • Disconnect
    • Dispose
    • Send message
  • FIX Session
    • Persistent session
    • Session state
    • Sequence number handling
    • Session qualifier
  • FIX Message
    • Create
    • Get field
    • Add field
    • Set field
    • Remove field
    • Repeating group
    • User defined fields
    • Clone message
  • FIX Prepared Message
    • Create
    • Add field
    • Set field
  • Repeating Group API
    • Indexing Repeating Group
    • Working with Repeating Groups through API
    • Repeating Group Pool
    • Get Repeating Group
    • Get Entry
    • Get nested group
    • Add new Repeating Group to message
    • Add new Entry to Repeating Group
    • Remove Entry from Repeating Group
    • Leading tag self-maintaining
    • ITagList interface
    • Validation
    • Copying
    • Finishing work with Repeating Group API
  • Validation
    • Initialization
    • Validation
  • Monitoring and Administration
    • Overview
    • Response result codes
    • Supported commands
  • Recovery
    • Store-and-forward
    • Gap fill
    • Fail-over
  • Configuration
    • Global configuration
    • Server Behavior
    • Queue and Storage
    • Validation
    • Administrative plugin
    • Session’s configuration
    • Configure SeqNum fields length
    • Definition of session’s configuration via properties file
    • Definition of session’s configuration via XML file
    • Loading of session’s configuration
  • TLS Support
    • SSL/TLS configuration
    • How to define an SSL certificate
    • How to use sslPort and requireSsl configuration options
    • Configuration examples
    • Diagnostic and troubleshooting
  • Other Topics
    • Log files
    • FAQ
    • Troubleshooting

FIX Prepared Message

Create

A prepared message can be created in three different ways:

  1. Create a skeleton and set fields
  2. Parse a raw FIX message (byte array)
  3. Create a message from existing FixMessage

To create a FIX prepared message please use the IFixSession.PrepareMessage() and IFixSession.PrepareMessageFromString() methods. Thereafter you can set/change the desired field values of a message and send it to the counter-party many times.

For example:

MessageStructure ms = new MessageStructure();
ms.ReserveString(148, 11);
FixMessage pm = null;
try 
{
    pm = session.PrepareMessage("B", ms);
} 
catch (PreparedMessageException e) 
{
    //handle error of building prepared message
}

pm.Set(148, "Hello there");
session.SendMessage(pm);

To parse a string containing a raw FIX message use the IFixSession.PrepareMessageFromString(byte[] message, string type, MessageStructure structure) method.

For example:

string message = "5=ABRA\u00016=KADABRA\u0001";
MessageStructure ms = new MessageStructure();
ms.Reserve(5,4);
ms.Reserve(6,7);
FixMessage pm = null;
try 
{
    pm = session.PrepareMessageFromString(message.GetBytes(), "A", ms);
} 
catch (PreparedMessageException e) 
{
    //handle error of building prepared message
}

session.SendMessage(pm);

To create prepared message from FixMessage object please use IFixSession.PrepareMessage(FixMessage message, string type, MessageStructure structure) method:

FixMessage list = new FixMessage();
list.AddTag(1, "TestValue");
MessageStructure ms = new MessageStructure();
ms.Reserve(1, 9);
FixMessage pm = null;
try 
{
    pm = session.PrepareMessage(list, "A", ms);
} 
catch (PreparedMessageException e) 
{
    //handle error of building prepared message
}

session.SendMessage(pm);

Add field

To add a field to message use the MessageStructure.Reserve(int tagId, int length) method. Also you can give a hint to builder about field type with similar methods MessageStructure.ReserveString(int tagId, int length) and MessageStructure.ReserveLong(int tagId, int length). In the last case builder will be able to prepare more optimized structure for a new message.

Keep in mind, all tags in message will be in order in which you have reserved it. Length is strictly fixed. If length of the tag is undetermined, you can use MessageStructure.VariableLength constant as a length parameter in Reserve(int,int) method. In such case length will be auto adjusted. But keep in mind such way is much more slower then fixed size for field. You will get a best perfomance if you prepared message will have only fixed length fields.

If you reserved 5 bytes, content length of this tag should be equal to 5 bytes too. Otherwise engine will mark the length for such field as undetermined (MessageStructure.VariableLength) automatically. But there is an exception from this rule: if you try to set a numeric value (int, long, double) with a lover length, engine will automatically fill the tag value with leading "0" to the required length.

Fixed tag value length:

MessageStructure ms = new MessageStructure();
ms.Reserve(1, 9);
ms.ReserveLong(54, 1);

Variable tag value length:

MessageStructure ms = new MessageStructure();
ms.ReserveString(58, MessageStructure.VariableLength);
VariableLength

Set field

To change a field value use FixMessage.Set() method:

message.Set(148, "Hello there");
message.Set(54, 1);

In case of repeating groups you can use such way to set concrete tag value:

message.Set(58, 1, "Hello there");
message.Set(58, 2, "Hello there again");

Entries in repeating group have a numbers starting from 1.

In This Article
  • Create
  • Add field
  • Set field
Back to top Generated by DocFX