Child pages
  • FifteenMinuteGettingStarted
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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:

  • Template References
  • Advanced Message Template Loading

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);

See Also:

  • Custom Types
  • Custom Operators
    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);
  • No labels