Dashboard > OpenFAST > Home > FifteenMinuteGettingStarted
OpenFAST Log In | Sign Up   View a printable version of the current page.
FifteenMinuteGettingStarted
Added by Jacob Northey, last edited by Jacob Northey on Jul 09, 2008  (view change)
Labels: 
(None)

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.

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:

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

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

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

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

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:

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:

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

Output to file:

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

Creating and reading messages

Reading messages:

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

Creating messages:

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

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.1.5a Build:#411 Mar 16, 2006) - Bug/feature request - Contact Administrators

SourceForge.net Logo