Child pages
  • FifteenMinuteGettingStarted

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Get Started using OpenFAST in Fifteen Minutes

  • Load or Create Message Templates
    • Using FAST Templates defined in XML
    • Using Hardcoded Templates
  • Set up Message Streams
    • Using Standard IO Streams
    • Through Session Control Protocol (separate page)
  • Create and Read Messages

Loading XML FAST Templates

Use the XMLMessageTemplateLoader to load template from an XML template file or other XML input stream source.

Code Block
InputStream templateSource = new FileInputStream("templates.xml");
MessageTemplateLoader templateLoader = new XMLMessageTemplateLoader();
MessageTemplate[] templates = templateLoader.load(templateSource);

See also:

Creating Hardcoded Templates

Scalar Fields
Singleton pre-defined types and operators are defined in the classes Type and Operator. Use these to construct scalar fields. An optional unsigned integer field named "quantity" with a copy operator can be defined as:

Code Block
Scalar quantity = new Scalar("quantity", Type.U32, Operator.COPY, ScalarValue.UNDEFINED, true);

A field with a default value can be set up as:

Code Block
Scalar compid = new Scalar("cid", Type.STRING, Operator.CONSTANT, new StringValue("openfast"), false);

Group Fields
To create a quote group with two scalars bid and ask

Code Block
Scalar bid = new Scalar("bid", Type.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false);
Scalar ask = new Scalar("ask", Type.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false);
Field[] fields = new Field[] { bid, ask };
Group quote = new Group("quote", fields, false);

Sequence Fields
To create a sequence of parties

Code Block
Scalar name = new Scalar("name", Type.STRING, Operator.COPY, ScalarValue.UNDEFINED, false);
Scalar id = new Scalar("id", Type.STRING, Operator.COPY, ScalarValue.UNDEFINED, false);
Field[] fields = new Field[] { name, id };
Sequence parties = new Sequence("parties", fields, false);

Message Template
Putting it all together:

Code Block
Field[] fields = new Field[] { compid, quote, parties };
MessageTemplate contractTemplate = new MessageTemplate("contract", fields);

Setting up Message Streams

To create an input stream and register a single template:

Code Block
InputStream fastEncodedStream = new FileInputStream("marketdata.fast");
MessageInputStream messageIn = new MessageInputStream(fastEncodedStream);
messageIn.registerTemplate(63, marketDataTemplate);

Output to file:

Code Block
OutputStream out = new FileOutputStream("marketdata.fast");
MessageOutputStream messageOut = new MessageOutputStream(fastStream);
messageOut.registerTemplate(63, marketDataTemplate);

Creating and reading messages

Reading messages:

Code Block
Message message = messageIn.readMessage();
String compId = message.getString("compid"); // By name
int value = message.getLong(2); // By index

Creating messages:

Code Block
Message message = new Message(contractTemplate);
message.setString("compid", "openfast"); // by name
message.setInteger(2, 124); // by index
messageOut.writeMessage(message);

See also: