developers guide rap - the trading edition...

120
Developers Guide RAP - The Trading Edition ® R4.1

Upload: dohuong

Post on 04-Aug-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Developers Guide

RAP - The Trading Edition® R4.1

DOCUMENT ID: DC00794-01-0410-01LAST REVISED: October 2010Copyright © 2010 by Sybase, Inc. All rights reserved.This publication pertains to Sybase software and to any subsequent release until otherwise indicated in new editions ortechnical notes. Information in this document is subject to change without notice. The software described herein is furnishedunder a license agreement, and it may be used or copied only in accordance with the terms of that agreement.To order additional documents, U.S. and Canadian customers should call Customer Fulfillment at (800) 685-8225, fax (617)229-9845.Customers in other countries with a U.S. license agreement may contact Customer Fulfillment via the above fax number. Allother international customers should contact their Sybase subsidiary or local distributor. Upgrades are provided only atregularly scheduled software release dates. No part of this publication may be reproduced, transmitted, or translated in anyform or by any means, electronic, mechanical, manual, optical, or otherwise, without the prior written permission of Sybase,Inc.Sybase trademarks can be viewed at the Sybase trademarks page at http://www.sybase.com/detail?id=1011207. Sybase andthe marks listed are trademarks of Sybase, Inc. A ® indicates registration in the United States of America.Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and othercountries.Unicode and the Unicode Logo are registered trademarks of Unicode, Inc.All other company and product names used herein may be trademarks or registered trademarks of the respective companieswith which they are associated.Use, duplication, or disclosure by the government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of DFARS52.227-7013 for the DOD and as set forth in FAR 52.227-19(a)-(d) for civilian agencies.Sybase, Inc., One Sybase Drive, Dublin, CA 94568

Contents

CHAPTER 1: Getting Started .................................1RAP – The Trading Edition Basics ................................1Application Development with RAP - The Trading Edition

......................................................................1Learning About RAP Architecture ...............................2

Platform Architecture ........................................2Feed Handlers ..........................................3Publishers ...............................................3Subscribers ..............................................4RAPCache Database ....................................4RAPStore Database .....................................4Operations Console ....................................4Process Flow ............................................5Transfer and Truncation of Derived Data ...........5

Development Scenarios ...........................................6

CHAPTER 2: Customizing the RAP Messages andSchema........................................................9

RAP Data Stream Templates ....................................10Datatype Conversion ........................................10

Supported Datatypes for Message Flow ...........11Unsupported Datatypes ..............................12Integer Conversions ..................................13Date and Time Conversions .........................13Numeric Conversions .................................14Lookup Tables .........................................15Supported Datatypes for Data Transfer ...........15

RDS Template and Element Descriptions ................17Message Modeling .................................................20

Developers Guide iii

Modeling a RAP Message in a PowerDesigner LogicalData Model ................................................21

Developing a RAP Message Template from the RAPMessages Model ...........................................21

Converting a RAP Messages Model to a RAPCache orRAPStore Model ...........................................22

Converting a RAPCache or RAPStore Model to a RAPMessages Model ...........................................23

Impact and Lineage Analysis ...............................23Database Structure Modifications .............................24

Adding a New Table .........................................24Adding a New Column ......................................25

CHAPTER 3: Publisher API ..................................27Initialization .......................................................27Functions to Send Messages ....................................28Error Codes .........................................................30Publisher API Data Structures ..................................31Methods .............................................................32

pub_initialize ................................................33pub_beginMessage ..........................................34pub_cancelMessage .........................................35Set Field Methods ...........................................35pub_sendMessage ............................................37pub_flush .....................................................37pub_shutdown ...............................................37

Logging ..............................................................38Logging Levels ...............................................39Logging API Interfaces ......................................39

log_open ...............................................39log_init_resource .....................................40log_message ...........................................41log_rsrc_message .....................................41log_close ...............................................42

Contents

iv RAP - The Trading Edition

log_init_from_context ...............................42log_get_context ......................................43log_hexdump ..........................................43log_message_force ...................................44log_rsrc_message_force .............................45log_get_filename .....................................45log_get_rsrc_message ................................46

Resource Bundles ............................................47

CHAPTER 4: Developing a Custom Feed Handler ......49Example: Building a Market Data Message ...................51Feed Handler Shutdown .........................................52

Publisher Stop Function Processing .......................52Application Development Using Publisher API Stubs ...... 53

Generating a Publisher API Stub for a RAP Message ...54Exporting a Single Message Definition .............54Exporting a Set of Message Definitions ............54

Developing a Publisher API Stub ..........................55main() method stub ..................................56Developing the main() Method in a Stub ..........56publish_<msgName>_Message() Stub ..............57Developing with the

publish_<msgName>_Message() Stub ...........59Publisher API Stubs Example ...............................59

Testing a Custom Feed Handler ................................62Compiling a Feed Handler ..................................63Configuring the Publisher API .............................64

Publisher API XML Element Descriptions ..........64Publisher Sample Template .........................66

Creating a Custom Configuration File for the FeedHandler ....................................................67

Creating a Startup Script ...................................68Manually Registering a Publisher for Operations

Console ....................................................69

Contents

Developers Guide v

Configuring the Agent for a Publisher .............69Registering an Agent to the JINI Server ...........71Configuring Multiple Publishers ....................71Updating the Environment Variables for Custom

Publishers ...........................................72Testing with the Demo Subscriber ........................72

Demo Subscriber ......................................73Debugging a Custom Feed Handler ............................73Deploying a Custom Feed Handler .............................74

Configuring a Feed Handler for Other Languages ......75Configuring Subscribers for a Feed Handler .............75Tuning Performance .........................................77

CHAPTER 5: Demo Feed Handler ..........................79Running the Demo Feed Handler from the Command

Line ...............................................................79Recompiling the Demo Feed Handler .........................80Compiler Options for the Publisher API Shared Library ...80

CHAPTER 6: FAST Feed Handler Customization ........83Message Handler Plug-ins .......................................83Writing a Message Handler Plug-in for the FAST Feed

Handler ..........................................................84Writing a Message Handler Plug-in Initialize Function ... .85Arguments of the Message Handler Plug-in Initialize

Function .........................................................87Writing a Message Handler Plug-in Process Function ......88Arguments of the Message Handler Process Function .....90Writing a Message Handler Plug-in Finalize Function ......90Arguments of the Message Handler Finalize Function .....91Implementing the Shutdown Callback Method ..............92C API Definitions of Function Signatures for Building a

Message Handler ...............................................93

Contents

vi RAP - The Trading Edition

C API Definition of ffh_fast_message and its RelatedStructures .......................................................94

FAST Templates ...................................................96

APPENDIX A: FIX Message to Data Model Mappings ....99General Processing Notes .......................................99

Instrument Blocks ...........................................99Data Aggregation and Missing Data .......................99Determining RDS Message Types Based on FIX

Messages .................................................100Stock Instruments ...................................100Bond Instruments ....................................100Mutual Fund Instruments ...........................100Option Instruments .................................100Index Instruments ...................................101

Advertisement FIX Message ...................................101Stock Trade RDS Mapping .................................101Mutual Fund History RDS Mapping .......................102Bond Trade RDS Mapping ..................................102Option Trade RDS Mapping ................................102

Mass Quote FIX Message ........................................103Stock Quote RDS Mapping .................................103Bond Quote RDS Mapping .................................104

Security Status FIX Message ...................................104Stock History RDS Mapping ...............................104

Index ....................................................................105

Contents

Developers Guide vii

Contents

viii RAP - The Trading Edition

CHAPTER 1 Getting Started

Developers creating custom feed handlers should read this document for an introduction to theproduct architecture, and complete information on development tools and scenarios.

RAP – The Trading Edition BasicsRAP – The Trading Edition® (RAP) is a consolidated trading and risk data repository and dataservices platform for customers in the capital markets and investment management sectors.

RAP consolidates market data from vendor feeds, historical time series data, real-time tradesand quotes (TAQ) data, and reference data in one repository, which eliminates or reducesintraday and overnight batch processing, and supports model-driven quantitative trading andreal-time portfolio decisions by presenting subsets of data to various applications.

Application Development with RAP - The Trading EditionDevelopers create custom feed handlers using the Publisher API and other development tools.

Development tools provide a platform for developing custom feed handlers, and configurationfiles to aid in testing and deployment. RAP development tools include:

• Publisher API, provided as a shared library and as a debugging library• Two sample feed handlers• Templates for market data• PowerDesigner®, a graphical enterprise modeling environment• A database model and schema• PowerDesigner extensions, including a logical model for RAP messages and extended

physical models• Sample queries• Sample data• Configuration files

Review the RAP platform architecture. Then choose a development scenario that best meetsyour needs.

Developers Guide 1

Learning About RAP ArchitectureDetermine the best approach to developing your own applications.

1. Review RAP components and process flow.

2. Review RAP data stream (RDS) templates.

3. Review the RAP data model and tables.

4. Review the PowerDesigner extensions for RAP message modeling.

5. Review sample queries and run them with the preloaded sample data, to see reportingexamples.

6. Read related white papers:

• Using Sybase® NonStop IQ and EMC CLARiiON and EMC CLARiiON for Backup/Restore, High Availability, and Disaster Recovery at http://www.sybase.com/detail?id=1054761

• Time Series in finance: the array database approach at http://cs.nyu.edu/shasha/papers/jagtalk.html

• FinTime - a financial time series benchmark at http://www.cs.nyu.edu/cs/faculty/shasha/fintime.html

See also• RAP Data Stream Templates on page 10

• Message Modeling on page 20

• Data Model and Queries

Platform ArchitectureRAP - The Trading Edition platform architecture includes feed handlers, publishers, andsubscribers.

RAP writes in-bound market data to an in-memory cache database and a historical data store.The cache database is an Adaptive Server® Enterprise (ASE) database; the historical datastore is a Sybase® IQ database.

Unified Agent Framework (UAF) provides a common set of discovery services, and host agentplug-ins that manage server resources or perform various operations. Agent plug-ins canperform product-specific commands, including status, start, stop, and restart. The agent canalso help retrieve the log file of the server.

2 RAP - The Trading Edition

Figure 1: Platform Architecture

Feed HandlersFeed handlers direct inbound market data into the RAP environment. They are publishers thatmanage connectivity and message transformation directly from exchanges, like the NYSE, orconsolidated service providers, like Reuters.

RAP provides two sample feed handlers: the FAST feed handler and the demo feed handler.All other feed handlers are currently third party. RAP provides a common publisher API thatallows vendors to integrate proprietary data feeds.

PublishersPublishers format incoming market data messages, and forward those messages to asubscriber.

Messages are forwarded to a subscriber in an internal RAP data stream (RDS) format. Apublisher consists of a publisher API layer, and a network layer.

The publisher API is intended for Sybase feed handlers (demo feed handler and FAST feedhandler) and developers who want to map proprietary market data into RAP. The publisherAPI uses an RDS template-processing module that identifies the message type, formats the

CHAPTER 1: Getting Started

Developers Guide 3

messages, and calls the network layer. The network layer buffers messages into packets andsends the packets across multiple data streams to a subscriber.

SubscribersEach subscriber has two components: the open subscriber and a data stream handler. The opensubscriber handles interface issues and queues messages for the data stream handler, and thedata stream handler routes the messages to their final destination.

Each data stream listens for packets on one UDP broadcast channel. When a packet arrives ona channel, the subscriber checks and records the packet sequence number to determinewhether any packets are missing. If a packet is missing, the subscriber asks the publisher toresend the missing packet on the publisher resend channel.

RAP includes two data stream handlers: the RAPCache data stream handler and the RAPStoredata stream handler. The RAPCache data stream handler loads messages into Adaptive Server.The Store data stream handler loads messages into Sybase IQ. The demo subscribercomponent includes a demo data stream handler that you can configure to write messages to afile, or discard messages.

RAPCache DatabaseThe RAPCache database is an Adaptive Server® Enterprise database server, which providesnear real-time access to inbound market data messages.

Using this data store for current market data provides a separate memory space for thespecialized use of traders who require up-to-the-second information, but may not need the fullhistorical data held in the RAPStore database.

RAPStore DatabaseThe RAPStore database is a Sybase IQ disk-based repository that can store large (into thepetabyte range) amounts of historical data.

The RAPStore database can also support a high number of concurrent user connections.

Operations ConsoleOperations Console is a Web-based console that monitors system status and performs routineadministration tasks.

UAF plug-ins running on each server handle communication between Operations Consoleand RAP components. When an agent starts on a server, the agent starts all of its plug-ins andregisters with the JINI server. Operations Console queries the JINI server to learn about agentsand their plug-ins.

Communication between Operations Console and the plug-ins occurs via remote methodinvocation. Publisher and subscriber plug-ins communicate with publisher and subscribercomponents via TCP over a local socket. Each publisher and subscriber has an administrationchannel listening on a specific port. When Operations Console issues a command, the agent

4 RAP - The Trading Edition

intercepts the request, and contacts the component. The component returns a response throughthe agent back to Operations Console.

Process FlowMessage processing occurs in three phases: build, transfer, and load.

For all feed handlers and all configurations, RAP data processing takes place in three mainphases.

1. Build messages. In a custom feed handler, developers use the Publisher API to buildmessages from incoming data feeds. Likewise, the demo feed handler and FAST feedhandler use the Publisher API to build messages.

2. Transfer messages. During this phase, messages are transferred from a publisher to asubscriber.

3. Loading messages. Subscribers load messages into the RAPCache and RAPStoredatabases.

Transfer and Truncation of Derived DataRAP infrastructure supports high-speed transfer of derived data into the RAPStore, withminimal latency.

Applications store derived data in the RAPCache. The derived data (for example, calculationresults) is stored in lookup tables that are separate from the market data tables. To preservehistorical records, transfer derived data to the RAPStore.

Transfer rules determine when derived and market data is transferred. Administrators createmultiple transfer rules to specialize derived data management. There are two types of transferrule: scheduled and cache-full.

Truncation rules govern when derived and market data is deleted. Rules specify which of theoldest data to delete. There are two types of truncation rules: scheduled and cache-full.

Transfer rules and truncation rules are defined in the OpsConsole.

In high-volume systems, the RAPCache subscriber and RAPStore subscriber machines can beso busy processing incoming message flow that there is no capacity left to process filetransfers. For efficient high-volume operation, configure separate machines to process datatransfers.

For information on administering transfers and truncations, see the Operations Console UsersGuide.

See also• Lookup Tables on page 15

• Supported Datatypes for Data Transfer on page 15

CHAPTER 1: Getting Started

Developers Guide 5

Development ScenariosChoose the degree of customization your application requires.

When choosing a development scenario, note that they are all related. If you are developing acustom feed handler, you need to customize the messages and schema. Likewise, if youcustomize messages and schema, you need to modify the feed handler.

Table 1. RAP Development Scenarios

Scenario Description

Customize the RAP messages and schema Add a new table or column to the RAPCache andRAPStore.

Develop a custom feed handler from a RAP Mes-sages model

Follow either scenario for message modeling:

1. Model a RAP message in PowerDesigner.

2. Generate a RAP message template.

3. Generate a Publisher API stub.

4. Generate a physical RAPCache and RAP-Store model.

Or:

1. Model the database tables in the RAPCacheor RAPStore model.

2. Generate the RAP Messages model from theRAPCache or RAPStore physical model.

3. Generate message templates and PublisherAPI stubs.

4. Generate the other physical data model(RAPCache or RAPStore, whichever you didnot create or update in the first step).

Develop a custom feed handler Use the Publisher API, the logging API, and con-figuration files to develop and deploy a customfeed handler.

(Optional) Accelerate feed handler developmentusing Publisher API stubs.

6 RAP - The Trading Edition

Scenario Description

Customize the FAST feed handler Customize the FAST feed handler by writing amessage handler plug-in.

Follow this process when the incoming datastream is encoded in the FAST protocol. You canimplement a subset of the Sybase FAST feedhandler, process message types other than thosedefined in the Sybase FAST templates library, orperform different initialization, processing, orlogging.

See also• Chapter 2, Customizing the RAP Messages and Schema on page 9

• Chapter 4, Developing a Custom Feed Handler on page 49

• Message Modeling on page 20

• Chapter 6, FAST Feed Handler Customization on page 83

CHAPTER 1: Getting Started

Developers Guide 7

8 RAP - The Trading Edition

CHAPTER 2 Customizing the RAP Messages andSchema

Add a new table or column to the RAPCache and RAPStore.

PrerequisitesReview information about the RAP data stream (RDS) templates, including supporteddatatypes for messages and data transfer, datatype conversions, and the template structure andelements.

Update messages and schema manually or by using message modeling to integratedevelopment of RAP message templates (also called RDS templates) with physical datamodels for your RAP databases. The overall process is the same in either case. Integratedmessage modeling simply expedites changes and helps ensure consistency across the system.

Task

1. Modify the RAPCache and RAPStore database schemas.

Best practice is to update the physical data models and generate the schema. See DataModel and Queries > DDL Script Generations.

2. Create or modify RDS message templates:

For this type ofdatabase change...

Do this...

Adding a new table Create a new template. Either:

• Code it manually, or,

• Generate the RAP Messages model for that table from theupdated physical data model, and export the template file.

Adding a new column toan existing table

Modify existing templates as needed. Either:

• Update templates manually, or,

• Generate the RAP Messages model for updated tables from thephysical data model, and export the template files.

3. If you change data types or add new fields, also change them in your feed handler.

4. Restart publishers and subscribers.

See also• Adding a New Table on page 24• Adding a New Column on page 25

Developers Guide 9

• Data Model and Queries

RAP Data Stream TemplatesRDS templates are XML documents that represent the data structure of specific messagetypes.

The Publisher API and subscribers look up information about message formats in a set of RDStemplates. The Publisher API uses templates to build the messages it sends to subscribers.Subscribers use templates to parse messages and store them in a database.

The use of RDS templates minimizes the network bandwidth required for messagetransmission. RDS templates also increase processing efficiency by minimizing the number ofCPU cycles needed to process each message.

You must express all message types in the proper template format. A template includes allmessage fields, as well as the sequence of those fields. You must set each field within amessage in the order in which it is defined in the template.

The Publisher API locates templates using a directory passed into the publisher initializationmethod. All files in that directory are read into memory. A publisher or subscriber may use oneor more template files, and each file may contain one or more message definitions. Templatefiles are included in a /templates folder. Each feed handler and subscriber has its owncopy of these files.

The template processor is included in libpublisher.so with other shared library files.For example, shared library files for the demo feed handler are inrap_install_folder/DemoFeedHandler/lib/libpublisher.so.

Note: Publishers and subscribers can reside on different computers, but the same templatesand the same version of the software must be used by both the publisher and subscriber.

Datatype ConversionRAPCache and RAPStore subscribers attempt automatic datatype conversion if the datatypesare compatible and no loss of precision occurs.

Automatic datatype conversion occurs between the RDS datatypes used to transfer messagesbetween the publisher and subscriber sides, and the database column datatypes used to storethe information.

See also• Set Field Methods on page 35

10 RAP - The Trading Edition

Supported Datatypes for Message FlowRAP supports the following datatypes for message flow.

Table 2. Supported datatypes for message flow

RDS data-type

Adaptive Server datatype Sybase IQ datatype

uint8 tinyint tinyint

uint16 unsigned smallint unsigned int (IQ has no unsignedsmallint)

uint32 unsigned int unsigned int

uint64 unsigned bigint unsigned bigint

sint8 smallint (Adaptive Server has no signed 8-bit integer)

smallint (IQ has no signed 8-bit in-teger)

sint16 smallint smallint

sint32 int int

sint64 bigint bigint

decimal( p, s ) numeric( p, s ) or decimal( p, s )

Limited to precision 38. Precision must bethe same on RAPCache and RAPStore.

numeric( p, s ) or decimal( p, s )

Limited to precision 38. Precisionmust be the same on RAPCache andRAPStore.

datetime datetime for granularity to 1/300th of asecond

timestamp

datetime2 bigdatetime for granularity to 6 decimalplaces

timestamp

date date date

time time time

time2 bigtime for granularity to 6 decimal places timestamp

string char(n) or varchar(n) n <255* char(n) or varchar(n) n <255*

Note:

• If you know that data for a column is always going to be shorter than a specific length, set nto a small as possible value for better performance.

• For precisions up to 18 digits (approximately), to gain maximum performance , usepub_setDecimalFieldFromMantissa instead of pub_setDecimalto setdecimal fields, if you can obtain the desired value in a format other than double precision.

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 11

• For precisions up to 38, use pub_setDecimalFieldFromString to set decimalfields.

• For RAPCache microsecond time granularity, as supported in RAPStore, your applicationmust use the bigdatetime and bigtime datatypes that support it. When using thesedatatypes, you must use the pub_setDateTime2Field andpub_setTime2Field methods which operate on these types.

See also• Unsupported Datatypes on page 12

• Integer Conversions on page 13

• Date and Time Conversions on page 13

• Numeric Conversions on page 14

• Lookup Tables on page 15

• Supported Datatypes for Data Transfer on page 15

• Example: Building a Market Data Message on page 51

• publish_<msgName>_Message() Stub on page 57

• Developing with the publish_<msgName>_Message() Stub on page 59

Unsupported DatatypesRAP does not support large object binary or text, money, float, bit datatypes, and char orvarchar over 255 characters datatypes for message flow. Some types supported for datatransfer are not supported for message flow.

RAP does not support these datatypes for message flow:

• LOB (large object binary or text)• MONEY datatype (however, SMALLMONEY is supported)• FLOAT• CHAR or VARCHAR datatypes with size greater than 255. However, note that these

datatypes are truncated at 255 characters.• BIT

In addition, RAP does not support RDS message definitions that reference a table that includesa CHAR or VARCHAR column that is non-null and has a default value, unless that column isexplicitly set by the RDS message.

RAP does not support these RAPCache datatypes for high-speed data transfer:

• text• image• unitext

12 RAP - The Trading Edition

See also• Supported Datatypes for Message Flow on page 11• Integer Conversions on page 13• Date and Time Conversions on page 13• Numeric Conversions on page 14• Lookup Tables on page 15• Supported Datatypes for Data Transfer on page 15

Integer ConversionsThe available integer conversions depend on the integer type.

Subscribers implicitly convert any signed or unsigned integer to a larger signed integer.Subscribers implicitly convert unsigned integers only to a larger unsigned integer.

Subscribers implicitly convert any signed or unsigned integer into a NUMERIC or DECIMALdatatype with (precision minus scale) greater than or equal to precision required to representthe maximum value of the type of the integer. To convert unsigned 64-bit integers into numericdatatypes, you must use precision of at least 19.

See also• Supported Datatypes for Message Flow on page 11• Unsupported Datatypes on page 12• Date and Time Conversions on page 13• Numeric Conversions on page 14• Lookup Tables on page 15• Supported Datatypes for Data Transfer on page 15

Date and Time ConversionsAvailable date and time conversions depend on the datatype.

• Subscribers implicitly convert TIME datatypes to BIGTIME datatypes by setting themicrosecond portion to 0.

• Subscribers implicitly convert DATETIME datatypes to BIGDATETIME datatypes bysetting the microsecond portion to 0.

• Subscribers implicitly convert DATE datatypes to DATETIME or BIGDATETIMEdatatypes by setting the time portion to 0.

See also• Supported Datatypes for Message Flow on page 11• Unsupported Datatypes on page 12• Integer Conversions on page 13• Numeric Conversions on page 14• Lookup Tables on page 15

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 13

• Supported Datatypes for Data Transfer on page 15

Numeric ConversionsAvailable numeric conversions depend on the datatype characteristics.

Table 3. Datatype conversions

Datatype Converts to Comments

NUMERIC orDECIMAL

SIGNED INTEGER A NUMERIC or DECIMAL data-type with scale 0 can be convertedinto a SIGNED INTEGER, providedthe precision required to representthe maximum value of the integer isgreater than or equal to the precisionof the NUMERIC or DECIMAL da-tatype.

NUMERIC orDECIMAL

INTEGER NUMERIC or DECIMAL datatypeswith a scale other than zero cannot beconverted into INTEGERS, and nu-merics cannot be converted into UN-SIGNED INTEGERS.

NUMERIC orDECIMAL

Other NUMERIC or DECIMAL datatypes A NUMERIC or DECIMAL data-type can be converted into other NU-MERIC or DECIMAL datatypes,provided that the scale of the targettype is greater than or equal to thescale of the source NUMERIC, andthe precision of the target NUMER-IC is greater than or equal to the pre-cision of the source NUMERIC plusthe difference between the targetscale and the source scale.

ExamplesUse these examples as a reference for some of the available conversions.

NUMERIC(4, 2) can be converted into a NUMERIC(4, 4)NUMERIC(2, 2) can be converted into a NUMERIC(4, 4)NUMERIC(2, 4) cannot be converted into a NUMERIC(4, 0)NUMERIC(2, 4) cannot be converted into a NUMERIC(3, 6)

See also• Supported Datatypes for Message Flow on page 11• Unsupported Datatypes on page 12• Integer Conversions on page 13• Date and Time Conversions on page 13

14 RAP - The Trading Edition

• Lookup Tables on page 15

• Supported Datatypes for Data Transfer on page 15

Lookup TablesLookup tables, which contain derived data, are loaded during initialization.

The lookup column must be convertible into the RDS type of the lookup data. The lookupreturn column datatype must be convertible into the datatype of the destination column of thetarget table.

The data transfer facility for derived data does not attempt to automatically maintaindependencies across tables. Developers, or Ops Console administrators, must define transferrules to accommodate transfer of any dependent data.

See:

• Installation and Configuration Guide > Configuring High-Speed Transfer of Derived Data• Operations Console Users Guide > Data Administration

See also• Supported Datatypes for Message Flow on page 11

• Unsupported Datatypes on page 12

• Integer Conversions on page 13

• Date and Time Conversions on page 13

• Numeric Conversions on page 14

• Supported Datatypes for Data Transfer on page 15

• Transfer and Truncation of Derived Data on page 5

Supported Datatypes for Data TransferRAP supports the following datatypes for data transfer.

Table 4. Supported datatypes for data transfer

RAPCache datatype RAPStore datatype Comment

[unsigned] bigint [unsigned] bigint

[unsigned] int [unsigned] int

[unsigned] smallint [unsigned] smallint

tinyint tinyint

bit bit

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 15

RAPCache datatype RAPStore datatype Comment

decimal (p,s) decimal (p,s) Limited to precision 38.Precision must be the sameon RAPCache and RAP-Store.

numeric (p,s) numeric (p,s) Limited to precision 38.Precision must be the sameon RAPCache and RAP-Store.

float double

double double

real real

money money

smallmoney money

[var]binary(n) [var]binary(n) Limited by RAPCachepage size.

[var]char(n) [var]char(n) Limited by RAPCachepage size.

unichar(n) binary(n) Limited by RAPCachepage size.

univarchar(n) varbinary(n) Limited by RAPCachepage size.

date date

time time

smalldatetime smalldatetime, datetime RAPCache type accurateto 1 minute.

datetime datetime RAPCache type accurateto 1/300th seconds.

bigtime time RAPCache type accurateto 1 microsecond.

bigdatetime datetime RAPCache type accurateto 1 microsecond.

timestamp varbinary(8)

Note: If a message contains an empty string, the empty string is stored as NULL in theRAPCache database and is stored as an empty string in the RAPStore database.

16 RAP - The Trading Edition

See also• Supported Datatypes for Message Flow on page 11

• Unsupported Datatypes on page 12

• Integer Conversions on page 13

• Date and Time Conversions on page 13

• Numeric Conversions on page 14

• Lookup Tables on page 15

• Transfer and Truncation of Derived Data on page 5

RDS Template and Element DescriptionsElement descriptions for the available RDS template elements, and a sample template.

Table 5. RDS template XML element descriptions

Element Description

Template Root element for the template.

MessageDefnList A list of one or more message definitions.

MessageDefn Information that defines a single message type.

MessageDesc Description of the type of market data message, for example, StockQuote. This element is used only for descriptive purposes, and cancontain any string.

MessageType Unique number representing the type of market data message. Thisnumber must uniquely identify the message type across all messagedefinitions within all templates. The value can contain any integerfrom 1 – 65535.

DestTableName Name of the database table into which the message should be stored.There is one database table per message type. The value can containany string.

FieldDefnList A list of one or more field definitions.

FieldDefn Information that defines a single field.

FieldName Name of the field. The value can contain any string.

IntegerField Indicates that the field is some type of integer.

IntegerDataType Data type of an integer field. Valid values: uint8, uint16, uint32,uint64, sint8, sint16, sint32, sint64.

DecimalField Indicates that the field is a decimal value. The field definition cancontain only one of: IntegerField, DecimalField, StringField, Date-Field, TimeField, DateTimeField, DateTime2Field, Time2Field.

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 17

Element Description

Precision Precision of a decimal field. Maximum precision allowed is 38 digits.

Scale Scale of a decimal field (the number of digits after the decimal point).Maximum scale can be no larger than the precision (38).

StringField Indicates that the field is a string.

DateField Indicates that the field is a date. The field definition can contain onlyone of: IntegerField, DecimalField, StringField, DateField, Time-Field, DateTimeField, DateTime2Field, Time2Field.

TimeField Indicates that the field is a time.

Time2Field Indicates that the field is a bigtime (granularity to 6 decimal places).The field definition can contain only one of: IntegerField, Decimal-Field, StringField, DateField, TimeField, DateTimeField, Date-Time2Field, Time2Field.

DateTimeField Indicates that the field is a datetime.

DateTime2Field Indicates that the field is a bigdatetime (granularity to 6 decimalplaces). The field definition can contain only one of: IntegerField,DecimalField, StringField, DateField, TimeField, DateTimeField,DateTime2Field, Time2Field.

DestColumnName Name of the column into which the field data should be stored. Thereis one column per field. The value of this element can contain anystring.

Lookup Indicates that the data in the field should be used as a lookup foranother table. This is an optional element. If it does not appear in afield definition, then no lookup is required.

LookupTableName Name of the table to use to look up a value.

LookupColumnName Name of the column to use to look up a value.

LookupColumnReturn Name of the column from which to return data when doing a lookup.

Sample RDS TemplateEach RDS template file in the templates folder defines the information required by thePublisher API and subscribers. Subscribers allow lookups of a field value from a databasetable before inserting the value into the RAP schema. The RDS sample template allows theinformation required for this lookup to be defined.

A sample template is shown below. An XML schema (.xsd) describing the XML format isincluded with the product.

Note: Refer to the installed sample template files in the templates directory for eachpublisher and subscriber for the actual template content.

18 RAP - The Trading Edition

<Template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi=noNamespaceSchemaLocation="..template.xsd"> <MessageDefnList> <MessageDefn> <MessageDesc>Stock Quote</MessageDesc> <MessageType>4</MessageType> <DestTableName>STOCK_QUOTE</DestTableName> <FieldDefnList> <FieldDefn> <FieldName>Instrument</FieldName> <StringField/> <DestColumName>INSTRUMENT_ID</DestColumnName> <Lookup> <LookupTableName>INSTRUMENT</LookupTableName> <LookupColumnName>TRADING_SYMBOL</LookupColumnName> <LookupColumnReturn>INSTRUMENT_ID</LookupColumnReturn> </Lookup> </FieldDefn > <FieldDefn> <FieldName>Quote Date</FieldName> <DateField/> <DestColumnName>QUOTE_DATE</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Quote Sequence Number</FieldName> <IntegerField> <IntegerDataType>sint32</IntegerDataType> <DestColumnName>QUOTE_SEQ_NBR</DestColumnName> <FieldDefn> <FieldName>Trading Symbol</FieldName> <StringField/> <DestColumnName>TRADING_SYMBOL</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Quote Time</FieldName> <DateTimeField/> <DestColumnName>QUOTE_TIME</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Ask Price</FieldName> <DecimalField> <Precision>18</Precision> <Scale>4</Scale> </DecimalField> <DestColumnName>ASK_PRICE</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Ask Size</FieldName> <IntegerField> <IntegerDataType>sint32</IntegerDataType> </IntegerField> <DestColumnName>ASK_SIZE</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Bid Price</FieldName> <DecimalField>

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 19

<Precision>18</Precision> <Scale>4</Scale> </DecimalField> <DestColumnName>BID_PRICE</DestColumnName> </FieldDefn> <FieldDefn> <FieldName>Bid Size</FieldName> <IntegerField> <IntegerDataType>sint32</IntegerDataType> </IntegerField> <DestColumnName>BID_SIZE</DestColumnName> </FieldDefn> </FieldDefnList> </MessageDefn> </MessageDefnList></Template>

Note: The installed sample template has only one <MessageDefn> ... </MessageDefn>. Atemplate for a custom feed handler can include as many as needed.

See also• Set Field Methods on page 35

Message ModelingYou can integrate message customizations with the database schema and Publisher API codeto aid production deployment of feed handlers. You can start by modeling the message or startwith the database model.

If you start by modeling the message:

1. Model a RAP message in PowerDesigner.2. Generate a RAP message template.3. Generate a Publisher API stub.4. Generate a physical RAPCache and RAPStore model.

If you start with the database model:

1. Model the database tables in the RAPCache or RAPStore model.2. Generate the RAP Messages model from the RAPCache or RAPStore physical model.3. Generate message templates and Publisher API stubs.4. Generate the other physical data model (RAPCache or RAPStore, whichever you did not

create or update in the first step).

In both scenarios you can validate a model using custom checks for RAP messages, in additionto standard PowerDesigner checks for all models.

Both scenarios require the PowerDesigner extensions for RAP.

20 RAP - The Trading Edition

This document summarizes tasks for these scenarios. For details, see Data Model andQueries.

Modeling a RAP Message in a PowerDesigner Logical Data ModelCreate or modify messages in the RAP Messages model.

PrerequisitesSet up the PowerDesigner extensions.

This is a summary. See Data Model and Queries > RAP Message Model Development fordetails.

Task

1. Create a new RAP messages model. Either:

• Use the RAP Messages category item, to create the model and automatically extend it,or

• Create a logical data model and then extend it.

2. Add message definitions to the model.

3. Define message properties.

4. Validate the model.

See also• Developing a RAP Message Template from the RAP Messages Model on page 21

• Converting a RAP Messages Model to a RAPCache or RAPStore Model on page 22

• Converting a RAPCache or RAPStore Model to a RAP Messages Model on page 23

• Impact and Lineage Analysis on page 23

Developing a RAP Message Template from the RAP Messages ModelExport message definitions to a RAP template file.

PrerequisitesCreate and validate your RAP messages model.

This is a summary. See Data Model and Queries > Model Generation for details.

Task

1. In PowerDesigner, open the RAP Messages model.

2. Either:

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 21

• Export a single message definition to a RAP template file from its Properties page.Or,

• Export selected message definitions with the Extended Generation Tool.

PowerDesigner creates message_name.xml files for the selected messages in thelocation you specify.

3. Review the templates.

4. To add or modify message templates, either:

• Make the modifications in the RAP Messages model and reexport message definitions,or,

• Make the modifications in the template, then import the template file intoPowerDesigner.

See also• Modeling a RAP Message in a PowerDesigner Logical Data Model on page 21• Converting a RAP Messages Model to a RAPCache or RAPStore Model on page 22• Converting a RAPCache or RAPStore Model to a RAP Messages Model on page 23• Impact and Lineage Analysis on page 23

Converting a RAP Messages Model to a RAPCache or RAPStore ModelFor RAPCache, generate a Sybase Adaptive Server Enterprise model. For RAPStore, generatea Sybase IQ model.

This is a summary. See Data Model and Queries > Model Generation for details.

1. In PowerDesigner, generate a physical data model for the database target you want.

You can generate a new physical data model or update an existing one.

2. Enable transformations for the appropriate extension, RAPCache or RAPStore.

3. Perform postgeneration tasks to add or edit indexes, set physical options, and add foreignkeys as needed.

4. Add other tables or columns as needed. Either:

• Modify the physical data model, then generate the RAP messages logical model fromit, or,

• Modify the RAP messages logical model and regenerate the physical model.

5. Analyze the impact of changes as you make them.

See also• Modeling a RAP Message in a PowerDesigner Logical Data Model on page 21• Developing a RAP Message Template from the RAP Messages Model on page 21• Converting a RAPCache or RAPStore Model to a RAP Messages Model on page 23• Impact and Lineage Analysis on page 23

22 RAP - The Trading Edition

Converting a RAPCache or RAPStore Model to a RAP Messages ModelGenerate the RAP Messages logical model from either the RAPCache or RAPStore physicaldata model.

PrerequisitesSet up the PowerDesigner extensions.

This is a summary. See Data Model and Queries > Model Generation for details.

Task

1. In PowerDesigner, from the physical data model, generate a new logical data model orupdate an existing one.

2. Enable transformations for the RAPMessage extension.

3. Perform postgeneration tasks to set the message type and adjust lookup fields.

See also• Modeling a RAP Message in a PowerDesigner Logical Data Model on page 21

• Developing a RAP Message Template from the RAP Messages Model on page 21

• Converting a RAP Messages Model to a RAPCache or RAPStore Model on page 22

• Impact and Lineage Analysis on page 23

Impact and Lineage AnalysisWith impact and lineage analysis, you can determine the full impact of changes to any objectin the integrated model.

Impact analysis shows the effect of an action on the objects that depend on the initial object.

Lineage analysis identifies the objects that influence the initial object.

You can perform these analyses on:

• A message definition or any of its properties in the RAP Messages logical data model• A table or column in the RAPCache or RAPStore physical data model

The results shows the effect of a change throughout the logical and physical data models.

See also• Modeling a RAP Message in a PowerDesigner Logical Data Model on page 21

• Developing a RAP Message Template from the RAP Messages Model on page 21

• Converting a RAP Messages Model to a RAPCache or RAPStore Model on page 22

• Converting a RAPCache or RAPStore Model to a RAP Messages Model on page 23

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 23

Database Structure ModificationsWhen you modify a message template, you may also need to modify the associated schemaand database tables or columns.

Warning! Do not use the following characters in any schema names, table names, indexnames, or partition names within a RAPCache or RAPStore database: ., ", [, or ].

Adding a New TableAdd a new table to your RAPStore and RAPCache database schemas if the standard schemasdo not suit your needs, or to use custom messages.

1. Modify the RAPStore and RAPCache database schemas:

a) In PowerDesigner, modify both the RAPStore and RAPCache physical data models(PDMs), and generate data definition language (DDL) scripts for the new table.

b) Run the scripts to update the database. See Data Model and Queries > DDL ScriptGeneration.

2. Create a new RDS message template:

a) Create a new RDS message definition, specifying the new table as the destinationtable.

b) Ensure that the message type has a unique value across all RDS message definitions.c) For each column in the new database table, add a field definition block to the message

definition.d) If you create message definitions in the RAP Messages model, export them to a

message_name.xml template file.e) Ensure that all publishers and subscribers are updated with the new RDS message

templates by copying the new information to all subscribers.

3. Modify the publisher code:

a) Make a call to the pub_beginMessage API method specifying the new messagedefinition's message type.

b) For each field in the message, call the appropriate pub_set<type>Field APImethod to pass in the field data.

c) For fields that can be null, test for null and call pub_SetNullField.d) Call the pub_sendMessage API to send the data.

4. Stop, shut down, and restart subscribers and publishers for the changes to take effect.

See also• pub_beginMessage on page 34• Set Field Methods on page 35• pub_sendMessage on page 37

24 RAP - The Trading Edition

• RDS Template and Element Descriptions on page 17

• Adding a New Column on page 25

• Data Model and Queries

Adding a New ColumnAdd a new column to a table in your RAPStore and RAPCache database schemas if thestandard schemas do not suit your needs, or to use custom messages.

Note: The RAPStore schema does not support encrypted columns.

1. Modify the RAPStore and RAPCache database schemas:

a) In PowerDesigner, modify both the RAPStore and RAPCache physical data models(PDMs) and generate new data definition language (DDL) scripts.

b) Run the scripts to update the database. See Data Model and Queries > DDL ScriptGeneration.

2. Update RDS message templates:

a) Locate an RDS message file connected to the table you are adding the column to, andadd a field definition block to the file.

b) If you update message definitions in the RAP Messages model, export them to amessage_name.xml template file.

c) Ensure that all publishers and subscribers are updated with the new RDS messagetemplates by copying the templates into all subscribers.

3. Add a new call to the Publisher API:

a) Make a new Publisher API call to the appropriate pub_set<type>Field method,based on the datatype of the field.

b) For fields that can be null, test for null and call pub_setNullField.

4. To apply the changes, stop, shut down, and restart subscribers and publishers.

See also• RDS Template and Element Descriptions on page 17

• Set Field Methods on page 35

• Adding a New Table on page 24

• Data Model and Queries

CHAPTER 2: Customizing the RAP Messages and Schema

Developers Guide 25

26 RAP - The Trading Edition

CHAPTER 3 Publisher API

The Publisher API builds and processes messages that allow users to publish data in a standardformat.

The Publisher API is provided as a dynamically linked shared library. The shared libraryallows developers to compile a feed handler using any C or C++ compiler supported for theirenvironment.

Market data feed handlers invoke the Publisher API.

Subscribers must be running before the publisher is started so that the subscribers are ready toreceive messages when the publisher sends them.

If multiple publishers are running, each instance must use a unique UDP broadcast address.

Note: The term function is sometimes used in this document to refer to the Publisher APImethods.

Reentrant Code and the Shared LibraryThe shared library (libpublisher.so) supports one thread per message context. It isthread-safe in the context of a program running multiple messages with one thread permessage context. However, you cannot have one message context with multiple threads.

InitializationThe initialization method performs various operations to start the publication mechanism.

The initialization method:

• Obtains configuration parameters from publisher.xml and establishescommunications with subscribers. Access configuration property values by name throughthe Publisher API.

• Provides the Sybase Unified Agent Framework (UAF) interface. Operations Console usesthe UAF to provide an agent for each host on which RAP components are installed. TheUAF agent works with the Operations Console, receiving commands and requests forcomponent information and configuration. The UAF also forwards requests as needed toeach RAP component installed on the host.

• Initializes the version constant. Custom feed handlers must identify the version by settingstartup.version = PUB_STARTUP_VERSION. This constant tells the PublisherAPI the version of methods used in the feed handler. Each new version of the PublisherAPI (but not each version of RAP) increments this constant. Publisher API versioning isdesigned to simplify migration of custom feed handlers in future versions.

Developers Guide 27

• Preallocates message buffers. The Publisher API accepts messages from the feed handlerapplication and forwards them to subscribers. There are two types of buffering: the first isused to buffer messages, thereby saving memory allocation time for each new message;the second is used to resend packets.

• Initializes timing services. A timing service is a thread that sleeps or wakes according to aninterval timer. To ensure minimal latency of market data messages, this thread notifies amessage send service when it is time to send a partially full buffer. The thread also marksintervals for statistics collection.

• Initializes the heartbeat mechanism. To facilitate a highly-available configuration, eachRAP component must respond to a heartbeat sent by a separate program. The sender of theheartbeat message uses the response (or lack of response) to determine componentavailability. If necessary, a RAP FAILOVER is invoked. The heartbeat is initialized duringpub_initialize() processing.

• Initializes statistics. The Publisher API manages statistics on message traffic and reportsthese statistics to UAF on request.

• Initializes the resend infrastructure. If the Publisher API uses multicasting to publishmessages, any subscriber can request message resends. The Publisher API cachescandidates for resend in a circular buffer.

See also• Functions to Send Messages on page 28• Error Codes on page 30• Publisher API Data Structures on page 31• Methods on page 32• Logging on page 38• pub_initialize on page 33• pub_shutdown on page 37• Developing the main() Method in a Stub on page 56

Functions to Send MessagesSending messages requires a pub_beginMessage function, which signals the start of a newmessage, and a pub_sendMessage function, which places messages into the network buffer.

The publisher API code uses the field name to check that the pub_SetField() functions havebeen called in the correct order and that the data value passed in is the correct datatype.

Note: Each field within a message must be set in the order in which it is defined in thetemplate.

pub_beginMessageThe pub_beginMessage method signals to the RAP code that a new message is beingstarted.

28 RAP - The Trading Edition

Each network buffer has one network buffer header that indicates the sequential packetnumber being sent. Buffering ensures multicast ordering and allows possible resend requests.

The publisher API encodes each value sent to it via any pub_setField() method directly intothe wire-ready format buffer. Each successive value of a message is directly appended to makeone string that can be sent over the network. Since messages may contain as few as 60characters, multiple messages can be inserted into a single network packet buffer. Maximumtransmission unit (MTU) size determines the packet size.

Figure 2: Publisher API Message Flow

pub_sendMessageThe pub_sendMessage method places one or more messages into one wire format networkbuffer, and places a sequential network packet number on each packet it multicasts.

When the pub_sendMessage() method is called, the buffer to be sent is already in theappropriate format. The message template number used to construct the message is the firstfield of the wire format message.

pub_sendMessage() places one or more messages into one wire format network buffer.

CHAPTER 3: Publisher API

Developers Guide 29

When pub_sendMessage() is called, it must have been configured to define the channelsover which to multicast the packet. pub_sendMessage() is also responsible for placing asequential network packet number on each packet that it multicasts.

Publisher uses multiple channels for sending messages to maintain high performance throughparallelism.

Returns:

An error code or ERR_NONE (value 0).

See also• Initialization on page 27

• Error Codes on page 30

• Publisher API Data Structures on page 31

• Methods on page 32

• Logging on page 38

• pub_beginMessage on page 34

• pub_sendMessage on page 37

Error CodesThe Error codes table defines error codes.

Table 6. Error codes

Constant Description Value

ERR_NONE No error. Success. 0

ERR_PB_ Constants for error codes returned bythe publisher API are prefixed withERR_PB.

2000 -- 2999 This range is reservedfor the use of the publisher API.

See also• Initialization on page 27

• Functions to Send Messages on page 28

• Publisher API Data Structures on page 31

• Methods on page 32

• Logging on page 38

30 RAP - The Trading Edition

Publisher API Data StructuresPublisher API data structures hold information for callbacks, initialization, and market datamessages.

Callbacks StructureThis structure holds information for callbacks to the feed handler. Only one callback is listed.typedef struct {void (*shutdown)(void);/* notifies caller of shutdown request */} PUB_CALLBACKS;

Initialization InformationSample structure that holds information needed by the publisher for initialization. Seepub_initialize for an explanation of the members of this class.

Feed handler initialization code must specify the version of the Publisher API used, prior tocalling pub_initialize(). The current version is 1.

typedef struct {/* always set to PUB_STARTUP_VERSION */ size_t version;/* directory in which to locate configuration file */ const char * config_dir; /* directory in which to locate RDS templates */ const char * template_dir; /* indicates what type of publisher this is */ const char * component_subtype;/* enables/disables strict checking of messages as they are being built */ bool strict_check; /* indicates whether the feed handler has initialized the logger */ bool own_logger;/* callbacks to the feed handler */ PUB_CALLBACKS callbacks; } PUB_STARTUP;

Market Data Message InformationThis structure holds context information about a market data message that is being built to besent to subscribers.typedef struct {/* MESSAGE_DEFN pointer */void * message_defn; uint16_t current_field_num;/* location of destination message buffer */ uchar * dest_buffer;/* location of next fixed length value */ uchar * current_fixed_data;/* location of next variable length value */

CHAPTER 3: Publisher API

Developers Guide 31

uchar * current_variable_data/* length of market data message */ uint16_t message_length;}PUB_SEND_MESSAGE_CONTEXT;

See also• Initialization on page 27

• Functions to Send Messages on page 28

• Error Codes on page 30

• Methods on page 32

• Logging on page 38

• pub_initialize on page 33

MethodsFeed handlers invoke the publisher API to build and process messages.

The publisher API uses the template processing module as its source of information aboutmessage formats.

The following methods are members of the publisher API:

• pub_initialize• pub_beginMessage• pub_cancelMessage• A set of pub_setdatatypeField methods, including:

• pub_setInt8Field• pub_setInt16Field• pub_setInt32Field• pub_setInt64Field• pub_setUInt8Field• pub_setUInt16Field• pub_setUInt32Field• pub_setUInt64Field• pub_setDecimalField• pub_setDecimalFromMantissaField• pub_setDecimalFromStringField• pub_setDateField• pub_setTimeField• pub_setTime2Field• pub_setDateTimeField• pub_setDateTime2Field

32 RAP - The Trading Edition

• pub_setStringField• pub_setNullField

• pub_sendMessage• pub_flush• pub_shutdown

See also• Initialization on page 27• Functions to Send Messages on page 28• Error Codes on page 30• Publisher API Data Structures on page 31• Logging on page 38

pub_initializeInitializes the Publisher API.

Call this method before any other API in the Publisher API, and call it only once. Set theconstant startup.version = PUB_STARTUP_VERSION before callingpub_initialize.

Syntaxuint16_t pub_initialize( PUB_STARTUP * startup_settings );

Parameters

• PUB_STARTUP * startup_settings – contains information needed by the publisher toinitialize:

• size_t version – always set to PUB_STARTUP_VERSION.• char * config_dir – the directory for the publisher.xml file.• char * template_dir – the directory for RDS templates.• bool strict_check – a value indicating whether strict checking should be performed on

messages being built. true indicates that strict checking should be performed; Sybasesuggests that you use this setting during development. false indicates that strictchecking is not performed; Sybase recommends this setting for production mode.

• bool own_logger – true if the feed handler has initialized the log file, and false ifthe publisher should initialize the log file.

• char * component_subtype – a value indicating the type of publisher, for example,“FAST feed handler” or “demo feed handler.” This information is used to identify thetype of publisher when displaying information in Operations Console.

• PUB_CALLBACKS * callbacks – used to notify the Publisher API caller of events.RAP currently supports only one callback, which is a function to call if the publisherreceives a request to shut down.

CHAPTER 3: Publisher API

Developers Guide 33

The caller of the Publisher API may have to perform activities that need to occur beforethe Publisher API shuts down. The Publisher API invokes this callback function tonotify the caller that a request to shut down has been received. The caller must performthe necessary activities and then invoke the publisher's shutdown API.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

See also• Publisher API Data Structures on page 31

• main() method stub on page 56

• Initialization on page 27

• Developing the main() Method in a Stub on page 56

pub_beginMessageIndicates to the publisher that a new message is being built.

This method must be called before setting any of the fields on the message.

Syntaxuint16_t pub_beginMessage( uint16_t message_type, PUB_SEND_MESSAGE_CONTEXT * msg ).

Parameters

• uint16_t message_type – The type of message. The value for this parameter must matchthe message type indicated in the template.

• PUB_SEND_MESSAGE_CONTEXT * msg – The message context for the messagebeing built. This structure must be allocated before calling this method. To simultaneouslybuild multiple messages from multiple threads, allocate severalPUB_SEND_MESSAGE_CONTEXT structures and use one thread per message.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

See also• Functions to Send Messages on page 28

34 RAP - The Trading Edition

pub_cancelMessageIndicates to the publisher to cancel a message that was being built.

This method is called after beginMessage to free any resources being used by the messagecontext.

Syntaxuint16_t pub_cancelMessage( PUB_SEND_MESSAGE_CONTEXT * msg );

Parameters

• PUB_SEND_MESSAGE_CONTEXT * msg – The message context for the messagebeing built.

Returns

uint16_t error_code

An error code or ERR_NONE (value 0).

Set Field MethodsA group of methods that each set the value of a field in a message that is being built.

Syntaxuint16_t pub_setInt8Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, int8_t field_value );

uint16_t pub_setInt16Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, int16_t field_value );

uint16_t pub_setInt32Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, int32_t field_value );

uint16_t pub_setInt64Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, int64_t field_value );

uint16_t pub_setUInt8Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint8_t field_value );

uint16_t pub_setUInt16Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint16_t field_value );

uint16_t pub_setUInt32Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint32_t field_value );

uint16_t pub_setUInt64Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint64_t field_value );

uint16_t pub_setDecimalField( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name, double field_value );

CHAPTER 3: Publisher API

Developers Guide 35

The following method accepts a mantissa (the significant digits) and an exponent. The value ofthe decimal is mantissa x 10^exponent.uint16_t pub_setDecimalFieldFromMantissa( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name, int64_t mantissa, int8_t exponent );

uint16_t pub_setDecimalFieldFromString( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name, const char * value );

uint16_t pub_setDateField( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint32_t field_value );

uint16_t pub_setTimeField( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint32_t field_value );

uint16_t pub_setTime2Field( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uint64_t field_value );

uint16_t pub_setDateTimeField( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name, uint32_t dateField_value, uint32_t timeField_value );

uint16_t pub_setDateTime2Field( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name, uint32_t dateField_value, uint64_t timeFieldValue );

uint16_t pub_setStringField( PUB_SEND_MESSAGE_CONTEXT * msg, char * field_name, uchar * field_value);

uint16_t pub_setNullField( PUB_SEND_MESSAGE_CONTEXT * msg, const char * field_name );

Parameters

• PUB_SEND_MESSAGE_CONTEXT * msg – The message context for the messagebeing built.

• char * field_name – The name of the field being set. This name is used only when strictchecking is on.

• <data type> field_value – The value of the field to be placed into the message.• Date values – Express the number of days since the year 0000.• Time values – Express the number of milliseconds since midnight.• Datetime values – Consist of a 32-bit date value followed by a 32-bit time value.• String values – All string values are in UTF-8 format.

Returns

uint16_t error_code

An error code or ERR_NONE (value 0).

Note: The approximate precision of the pub_setDecimalField API is 15 digits,pub_setDecimalFieldFromMantissa API is 18 digits, andpub_setDecimalFieldFromString is 38.

36 RAP - The Trading Edition

See also• RDS Template and Element Descriptions on page 17

• Datatype Conversion on page 10

pub_sendMessageSends a market data message.

This method may or may not physically send a message. Messages are buffered until a packetis full, and then sent over the network.

Syntaxuint16_t pub_sendMessage( PUB_SEND_MESSAGE_CONTEXT * msg );

Parameters

• PUB_SEND_MESSAGE_CONTEXT * msg – The message context for the messagebeing built.

Returns

uint16_t error_code

An error code or ERR_NONE (value 0).

See also• Functions to Send Messages on page 28

pub_flushSends any buffered market data messages over the network to the subscribers.

Syntaxuint16_t pub_flush( void );

Returns

uint16_t error_code

An error code or ERR_NONE (value 0).

pub_shutdownDisconnects from the network and discards any resources being used by the publisher API.

This method is called when the feed handler is finished using the publisher API.

CHAPTER 3: Publisher API

Developers Guide 37

Syntaxuint16_t pub_shutdown( bool flush );

Parameters

• bool flush – Indicates whether any buffered messages should be sent beforedisconnecting.

Returns

uint16_t error_code

An error code or ERR_NONE (value 0).

See also• main() method stub on page 56• Initialization on page 27• Developing the main() Method in a Stub on page 56

LoggingRAP uses log4cxx version 0.10.0, an open source logging API, to log events in publishersand subscribers.

log4cxx allows you to control which log statements are sent to an output format. You canfind information about log4cxx at http://logging.apache.org/log4cxx/index.html.

The logging library is available to feed handler developers so that you can use the samelogging utility as the RAP modules. This allows events from custom feed handlers to belogged to the same log file as the file being used by RAP modules.

Logging messages in RAP - The Trading Edition are derived from resource bundles you cancustomize and localize. Resource bundles exist for each RAP component other than theRAPCache and RAPStore.

The default logging locale is U.S. English (en_US). Set the locale by modifying theRAP_LOCALE environment variable in the executable script file for each component.

Note: At higher log levels, more log information is reported, but processing may also beslower.

See also• Initialization on page 27• Functions to Send Messages on page 28• Error Codes on page 30• Publisher API Data Structures on page 31

38 RAP - The Trading Edition

• Methods on page 32

Logging LevelsUse the RAP log levels, defined in the logger.h file, during feed handler development.

Although log4cxx offers seven log levels, RAP maps to four levels, which are internallymapped to standard log4cxx.

An include file, logger.h, defines valid log levels:

LOGGER_DEBUGLOGGER_INFOLOGGER_WARNINGLOGGER_ERROR

The logging level set in the publisher API sets the base level of logging. You can override thislevel from the OpsConsole or in publisher.xml. For example, your feed handler codemight specify LOGGER_ERROR for best performance in a production environment. Todebug an issue, you might configure the level in publisher.xml to log at the debug level.

Logging API InterfacesModules that require logging must include the header file logger.h.

The following API functions are declared in logger.h:

• log_open• log_init_resource• log_message• log_rsrc_message• log_close• log_init_from_context• log_get_context• log_hexdump• log_message_force• log_rsrc_message_force• log_get_filename• log_get_rsrc_message

In addition to the method references, logger.h also contains the datatype:

typedef struct logger_context logger_context;

log_openInitialize RAPLogging API.

Call this method before any other API in the RAPLogging API, and call it only once.

CHAPTER 3: Publisher API

Developers Guide 39

Syntaxuint16_t log_open( char * filepath , uint16_t log_level);

Parameters

• char * filepath – The name and location of the log file. The file path can be either relativeor absolute.

• uint16_t log_level – The log level defined in the configuration file. The log level acts as afilter, ensuring that any message with a lower log level is ignored and not written into thelog file. You can define the log level in the configuration file as the default filter value, oryou can explicitly set the filter level dynamically.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_init_resourceInitializes a resource bundle.

Call this method after calling the log_open method, but before calling log_rsrc_message,log_rsrc_message_force, or log_get_rsrc_message.

Syntaxextern uint16_t log_init_resource( log_rb_id resource_id, const char * resourceName );

Parameters

• log_rb_id resource_id – The unique resource identifier. The resource ID must be greaterthan or equal to 1000.

• const char * resourceName – The base resource name of the resource bundle. Whensearching for a resource key, the method searches for the base name with the language andcountry codes appended. For example, it first searches formyresourcebundle_en_US.properties. If no such file exists, it searches for thebase name plus the language element, for example,myresourcebundle_en.properties. If no such file exists, it searches for onlythe base name, for example, myresourcebundle.properties.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

40 RAP - The Trading Edition

log_messageWrites the logging message and level into the log file.

Syntaxuint16_t log_message( uint16_t level, uint16_t err_number, char * message);

Parameters

• level – An include file, logger.h, defines valid log levels:

LOGGER_DEBUGLOGGER_INFOLOGGER_WARNINGLOGGER_ERROR

• unit16_t err_number – Error number.• char * message – Message to be written out.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_rsrc_messageLogs the message identified by the msgKey key at the specified logging level and against theerror code err_num.

The msgKey key resides within the resource bundle specified by the rsrc_id parameter.

Syntaxuint16_t log_rsrc_message( uint16_t level, uint16_t err_num, log_rb_id rsrc_id, const char * msgKey, va_list& args )

Parameters

• uint16_t level – The level to log the message at.

An include file, logger.h, defines valid log levels:

LOGGER_DEBUGLOGGER_INFOLOGGER_WARNINGLOGGER_ERROR

• unit16_t err_num – The error code of the error message being logged. Use error codesthat are greater than or equal to 10000 for custom development.

CHAPTER 3: Publisher API

Developers Guide 41

• log_rb_id rsrc_id – The unique identifier for the resource bundle. This ID is passed to thelog_init_resource API when initializing the resource bundle. Use IDs that are greater thanor equal to 1000 for custom development.

• char * msgKey – A key, or pointer, to the message in the resource bundle. Each messagein the resource bundle is paired with a key. Keys remain constant, and messages takecustom or localized content. Key-message pairs take this format:

MSG10101=Invalid message.• va_list& args – A variable number of arguments used for parameter substitution after the

resource message has been retrieved. To specify the position of the parameter, use n$. Forexample:

MSG1023=Unable to load file %1$s.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_closeCloses the log file and log hierarchy.

Call the log_close method must be called after other log operations, and call it only once.

Syntaxuint16_t log_close();

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_init_from_contextInitializes the RAPLogging API from an existing context created by a previous call tolog_open().

Use log_init_from_context to pass a logger instance to a shared library function. Call thisfunction before any other API in the RAPLogging API is invoked in the shared library.

Use this sequence of calls in your main executable to pass a logger instance to a shared library:

• Initialize the logger as usual by invoking log_open().• Get the pointer to the logger_context by invoking log_get_context().• Invoke your shared library function by passing it the logger_context pointer.

In your shared library function:

42 RAP - The Trading Edition

• Invoke log_init_from_context() by passing it the logger_context pointer as theargument.

• Invoke the log_message() function to log messages from your shared library.

Syntaxuint16_t log_init_from_context( logger_context * ctx );

Parameters

• logger_context * ctx – The logger_context pointer to be used to initialize theRAPLogging API in a shared library.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_get_contextReturns a pointer to the logger_context used by the current RAPLogging instance.

Use this pointer to initialize the RAPLogging API in a shared library.

Syntaxlogger_context * log_get_context( );

Returns

logger_context *, which is a pointer to the logger_context used by the currentRAPLogging instance.

log_hexdumpFormats and logs a traditional memory dump starting at the address supplied and the lengthsupplied. Use the supplied context string at the top and bottom to make it easy to identify. Usethe internal logger-> debug function to write it to the current log file.

A typical dump file (with the date, time, and thread values removed) looks similar to:

DEBUG rap4 - ===== DSHTable in Loader:Run New Work ======== DEBUG rap4 - 26583E0 >B0236800 00000000 C0C16502 00000000< .#h.......e..... 00000000 DEBUG rap4 - 26583F0 >36000700 00000000 90846502 00000000< 6.........e..... 00000010 DEBUG rap4 - 2658400 >58886702 00000000 F8C86E00 00000000< X.g.......n..... 00000020 DEBUG rap4 - 2658410 >F07E6502 00000000 707F6502 00000000< .~e.....p.e..... 00000030 DEBUG rap4 - 2658420 >687E6502 00000000<

CHAPTER 3: Publisher API

Developers Guide 43

h~e..... 00000040 DEBUG rap4 - ===== DSHTable in Loader:Run New Work ========

Syntaxlog_hexdump (char * contextString, void * address, long length)

Parameters

• char * contextString – The string printed at the beginning and end of the trace segmentfor identification.

• void * address – The beginning of the memory to dump.• long length – The number of bytes to log.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_message_forceWrites the logging message and level into the log file.

This method forces the message into the log file, regardless of the filter value of the log level.Set the filter value in the configuration file (RAP) or explicitly set by calling log_open() onthe feed handler side.

Syntaxuint16_t log_message_force( uint16_t level, uint16_t err_num, const char * message );

Parameters

• uint16_t level – For this method, the log level appears in the log file only as informational,as the message is always written into the log file.

• unit16_t err_num – Error number.• char * message – The message to be written out to the log.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

44 RAP - The Trading Edition

log_rsrc_message_forceWrites the logging message identified by the msgKey key at the specified level into the log file,regardless of the filter value of the log level. The msgKey key resides within the resourcebundle specified by the rsrc_id parameter.

The filter value of the log level determines what level of logging occurs, if any. You can set thefilter value in the configuration file or by calling log_rsrc_message_force()orlog_open() on the feed handler side. If the filter is set to exclude logging, this methodoverrides the filter and forces the messages into the log.

Syntaxuint16_t log_rsrc_message_force( const uint16_t level, const uint16_t err_num, log_rb_id rsrc_id, const char * msgKey, va_list& args)

Parameters

• uint16_t level – For this method, the log level appears in the log file only as informational,as the message is always written into the log file.

• uint16_t err_num – The error code of the message being logged. Use error codes that aregreater than or equal to 1000 for custom development.

• log_rb_id rsrc_id – The unique identifier for the resource bundle. This ID is passed to thelog_init_resource API during resource bundle initialization. Use IDs that are greater thanor equal to 1000 for custom development.

• char * msgKey – A key, or pointer, to the message in the resource bundle. Each messagein the resource bundle is paired with a key. Keys remain constant, and messages takecustom or localized content. Key-message pairs take this format:

MSG10101=Invalid message.

A pointer to the second operand for the comparison.• va_list& args – A variable number of arguments used for parameter substitution after the

resource message has been retrieved. To specify the position of the parameter, use n$. Forexample:

MSG1023=Unable to load file %1$s.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_get_filenameRetrieve the filename from the log context and return it to the caller.

Call log_get_filename to retrieve the log file location. Call it anywhere after log_open.

CHAPTER 3: Publisher API

Developers Guide 45

This method allows the log file and its location to be displayed on the OpsConsole. The fileand location are retrieved using the UAF agent property rap.service_logFile, whichmust be configured in agent-plugin.xml. It is unlikely that a custom feed handler wouldneed to call log_get_filename.

Syntaxchar * log_get_filename();

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

log_get_rsrc_messageFormats and writes to a buffer the message resource identified by msgKey, and returns thelength of the buffer required to hold the entire formatted message.

This method facilitates storing localized messages in the database. Calllog_get_rsrc_message to format the identified resource message into the named buffer.

• If the buffer is large enough to contain the formatted message, the value pointed to bybufferLen is updated to reflect the number of bytes used in the buffer.

• If the buffer is not large enough, the message is truncated in the available space, and thevalue pointed to by bufferLen is set to the number of bytes required to avoid truncation.

• If the buffer length is 0, then a NULL buffer can be passed in to determine the length of therequired buffer for the message, excluding the NUL terminator.

Syntaxuint16_t log_get_rsrc_message_force(char * buffer, size_t * bufferLen, log_rb_id rsrc_id, const char * msgKey, va_list& args)

Parameters

• char * buffer – Buffer where the formatted message should be written. This value may beNULL only if the buffer length is 0.

• size_t * bufferLen – On input, contains the size of the buffer in bytes; use 0 to get therequired buffer length. On return, contains the number of bytes used in the buffer. If theerror code indicates that the buffer was too small to hold the formatted message, the valuein bufferLen is the number of bytes required to format the message string, excluding thenull terminator.

• log_rb_id rsrc_id – The unique identifier for the resource bundle. This ID is passed to thelog_init_resource API during resource bundle initialization. Use IDs that are greater thanor equal to 1000 for custom development.

46 RAP - The Trading Edition

• const char * msgKey – A key, or pointer, to the message in the resource bundle. Eachmessage in the resource bundle is paired with a key. Keys remain constant, and messagestake custom or localized content. Key-message pairs take this format:

MSG10101=Invalid message.

A pointer to the second operand for the comparison.• va_list& args – A variable number of arguments used for parameter substitution after the

resource message has been retrieved.

Returnsuint16_t error_code

An error code or ERR_NONE (value 0).

When successful, bufferLen contains the number of bytes used in the buffer (return value lessthan or equal to input value). If the error code indicates that the buffer was too small to hold theformatted message, the value in bufferLen is the number of bytes required to format themessage string, excluding the null terminator (return value greater than input value).

Resource BundlesRAP - The Trading Edition includes resource bundles for each RAP component other thanRAPCache and RAPStore.

By default, resource bundles are localized for U.S. English. Create duplicate resource bundlesfor each locale you want to support. When adding resource bundles, include the two-digitcountry code and the two-digit language code in the file name. For example, to create aresource bundle for Japan, replace en_US in the default file name with ja_JP.

For each RAP component, the necessary resource bundles reside under the /lang folderparallel to the /bin folder holding the executable.

Table 7. Components and resource bundles

Component Resource bundles

FastFeedHandler util_en_US.properties

templateprocessor_en_US.properties

publisher_en_US.properties

fastfeedhandler_en_US.properties

fixmessagehandler_en_US.properties

CHAPTER 3: Publisher API

Developers Guide 47

Component Resource bundles

DemoFeedHandler util_en_US.properties

templateprocessor_en_US.properties

publisher_en_US.properties

demofeedhandler_en_US.properties

RAPCacheSubscriber util_en_US.properties

templateprocessor_en_US.properties

opensubscriber_en_US.properties

dbstreamhandlers_en_US.properties

RAPStoreSubscriber util_en_US.properties

templateprocessor_en_US.properties

opensubscriber_en_US.properties

dbstreamhandlers_en_US.properties

DemoSubscriber util_en_US.properties

templateprocessor_en_US.properties

opensubscriber_en_US.properties

dbstreamhandlers_en_US.properties

Each entry in a resource bundle is in Key=Message format. When creating localized bundles,replace the default Message text with text in the localized language. Do not change the keyvalue.

48 RAP - The Trading Edition

CHAPTER 4 Developing a Custom Feed Handler

Use the Publisher API, the logging API, and configuration files to develop and deploy acustom feed handler. Use the demo feed handler as an example, in addition to examples in thedocumentation.

PrerequisitesCreate or modify message templates and modify the corresponding RAPCache and RAPStoredatabase schemas, either manually or using RAP message modeling.

If you model messages, you can generate Publisher API stubs to automate some of the steps inthis task.

Task

1. Define and invoke the required data structures:

• PUB_CALLBACKS structure for callbacks used in shutdown processing.• PUB_STARTUP structure for initialization.• PUB_SEND_MESSAGE_CONTEXT structure for each market data message to be

built simultaneously. For example, the demo feed handler, which can send only onemessage at a time, creates exactly one PUB_SEND_MESSAGE_CONTEXT andreuses it. If it sent two at a time, it would need two separatePUB_SEND_MESSAGE_CONTEXT structs.

2. Initialize the publisher.

Call pub_initialize to perform initialization tasks, using settings inpublisher.xml.

Invoke a custom configuration file for any additional settings.

3. Set up messages to be sent.

• Call pub_beginMessage to indicate the start of a new message.

• For each field in the message, call the appropriate pub_set<type>Field methodfor your data.

• Call pub_sendMessage to send the message to the buffer, or callpub_cancelMessage to abandon the message.

Messages are buffered until a packet is full, and then sent over the network.

4. Add error checking and logging. Use either:

• The logging API methods, or• Your own logging functions.

Developers Guide 49

The installation includes some examples for the logger.

5. (Optional) Explicitly send any buffered messages to the subscribers. Either:

• Call pub_flush to flush messages, or,

• Use the bool flush parameter of pub_shutdown.

6. Process shutdown requests:

• Perform any feed handler activities that must occur prior to shutdown. This mayinclude finishing building messages in progress.

• Implement the shutdown callback method used in the PUB_CALLBACKS structure.This shutdown method should ensure that message publishing stops, that resourcesinitialized are freed and returned to the system, and that pub_shutdown is called.

• (Optional) Call pub_cancelMessage to cancel any messages being built and freeresources.

• Call pub_shutdown to disconnect from the network and discard any resourcesbeing used.

For example, at a high level, the main() method in the demo feed handler does thefollowing:

pub_initialize()

as long as the variable _continue is true read a line from the input file, wrapping to the top if necessary use that information to publish a messagego back to the top of the loop

pub_shutdown

The callback shutdown method sets _continue to false, which causes the main methodto stop and call pub_shutdown.

NextDefine configuration files.

Create a shell script to invoke the feed handler, and set up your environment to recognize it.

Compile and test the feed handler.

See also• Application Development Using Publisher API Stubs on page 53

50 RAP - The Trading Edition

Example: Building a Market Data MessageUse methods offered by the publisher API that have the feed handler build a message to send tothe RAP system.

The following sample code builds a market data message.

Note: For simplicity, error checking has been omitted from this example; however, productioncode should include error checking.

PUB_CALLBACKS * callbacks; PUB_STARTUP * startup; PUB_SEND_MESSAGE_CONTEXT * msg; uint16_t error_code; callbacks = Allocate a PUB_CALLBACKS structure; callbacks->shutdown = &myShutdownEventReceiver; startup = Allocate a PUB_STARTUP structure; startup->config_dir = configuration file directory or null; startup->template_dir = “templates”; startup->strict_check = false; startup->component_subtype = “FAST Feed Handler”; startup->callbacks = callbacks; startup.version = PUB_STARTUP_VERSION; pub_initialize( startup ); msg = Allocate a PUB_SEND_MESSAGE_CONTEXT structure; loop for each message { error_code = pub_beginMessage( <message_type>, msg ); error_code = pub_setInt32Field( msg, <field_name>, <field_value> ); error_code = pub_setStringField( msg, <field_name>, <field_value> ); error_code = pub_setInt16Field( msg, <field_name>, <field_value> ); error_code = pub_sendMessage( msg ); } error_code = pub_flush(); error_code = pub_shutdown( false ); Free the PUB_SEND_MESSAGE_CONTEXT structure; Free the PUB_CALLBACKS structure;

To build multiple messages simultaneously, allocate severalPUB_SEND_MESSAGE_CONTEXT structures and use one structure per message. Only onecall should initialize the publisher, not one per thread. Similarly, make only a single call to shutdown the publisher.

The feed handler does not need to call flush. This call is optional. The shutdown API accepts aBoolean parameter that indicates whether to flush any buffered messages before shuttingdown.

See also• Feed Handler Shutdown on page 52

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 51

• Application Development Using Publisher API Stubs on page 53

• Testing a Custom Feed Handler on page 62

• Debugging a Custom Feed Handler on page 73

• Deploying a Custom Feed Handler on page 74

• publish_<msgName>_Message() Stub on page 57

• Supported Datatypes for Message Flow on page 11

• Developing with the publish_<msgName>_Message() Stub on page 59

Feed Handler ShutdownA shutdown request is first sent to the publisher, which then calls the feed handler shutdowncallback.

Generally, shutdown requests are initiated by Operations Console. The publisher does notperform any shutdown actions upon receipt of this request, since the feed handler may need toperform its shutdown actions first. The feed handler should perform its shutdown activities,call pub_cancelMessage for any messages that are being built (or finish building them), andthen call the publisher shutdown method, pub_shutdown.

See also• Example: Building a Market Data Message on page 51

• Application Development Using Publisher API Stubs on page 53

• Testing a Custom Feed Handler on page 62

• Debugging a Custom Feed Handler on page 73

• Deploying a Custom Feed Handler on page 74

Publisher Stop Function ProcessingPublishers process stop messages received from the Operators Console using the appropriatecallback functions and flag checking.

You enable start and stop functioning by configuration settings in the agent-plugin.xmlfile.

When an operator presses Stop on the Operations Console, the agent sends a stop message tothe publisher's administration port so that the publisher can handle the termination request.

When the publisher receives the stop message:

• The publisher code defines a callback function. This function, called when a user selectsthe stop button of the publisher, sets a shutdown flag. For example, the shutdown flag in thedemo feed handler is:void publisherShutdown(){ feedhandler.setShutDown(true);

52 RAP - The Trading Edition

std::cout << "A shutdown process is requested" << std::endl;}

• The startup structure is passed to the publisher API through the publisher initializationcall. When the publisher API receives the stop message through the administration port, itcalls the callback function. For example, the callback function for the demo feed handleris:startup.callbacks.shutdown = publisherShutdown;

• In the publisher's loop of sending messages, the code occasionally checks the shutdownflag. When the flag is set to true, the code breaks out of the loop, performs cleanup, andends the process. For example, the shutdown flag in the demo feed handler is:if (feedhandler.isShutDown()){ throw "Shutdown has been requested.";}

Application Development Using Publisher API StubsAccelerate feed handler development using Publisher API stubs.

PowerDesigner extended generation facilities let you generate stub code for publishing a RAPmessage. The stub code provides an example of how to use the Publisher API to publish amethod.

Stub code is written in C, and includes:

• A main() method that calls:

• The pub_initialize method

• The method that publishes the message• The pub_shutdown method

• A method to publish one message type

Developers can use the generated code as a basis for their own feed handlers by defining thestart-up structure, adding error handling and logging, populating variables, and using otherPublisher API methods to achieve desired processing.

See also• Example: Building a Market Data Message on page 51

• Feed Handler Shutdown on page 52

• Testing a Custom Feed Handler on page 62

• Debugging a Custom Feed Handler on page 73

• Deploying a Custom Feed Handler on page 74

• Chapter 4, Developing a Custom Feed Handler on page 49

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 53

Generating a Publisher API Stub for a RAP MessageGenerate stub code from the RAP Messages model.Export one or more messages:

• To generate a stub for one message, export the message from the message definitionproperties sheet.

• To generate stubs for a selected set of messages, export the messages using the ExtendedGeneration tool.

See also• Developing a Publisher API Stub on page 55• Publisher API Stubs Example on page 59

Exporting a Single Message DefinitionGenerate a RAP message template file or a Publisher API stub for a message definition fromits properties sheet.

1. Right-click a message definition and choose Properties.

2. In Message Definition Properties, click the Preview tab.

Use the navigation bar below the Preview tab to show either the message template or thePublisher API stub for this RAP message.

3. Preview the code you want to generate:

• Review XML in the RAPMessage.Message Template subtab.• Review API stub code in the RAPMessage.Publisher API stub subtab.

PowerDesigner does not check that the model is valid when you generate from theproperties sheet.

4. Choose Save (Ctrl+S) and specify the target folder and file name for the generated file.

The file type to generate is determined by the preview subtab you are in when you save.

5. Click Save to start the generation.

See also• Exporting a Set of Message Definitions on page 54

Exporting a Set of Message DefinitionsWith the Extended Generation tool, generate RAP message templates, Publisher API stubcode, or both from selected message definitions.

Generate message definitions from anywhere in the RAP Messages model. Messagetemplates are generated as XML files in RAP data stream format. Stub code is generated inC.

54 RAP - The Trading Edition

1. From the PowerDesigner main menu, choose Tools > Extended Generation.

If this option is not available, make sure you are in the RAP Messages model.

2. Select Check Model (default).

With Check Model selected, PowerDesigner checks that the model is consistent beforegenerating files.

3. Enter the location for generated files.

4. In the Selection tab, select message definitions to generate.

5. (Optional) Name and save the selection for future use.

6. In the Generated Files tab, choose file types to generate:

Option Description

message_name.c Generate Publisher API stub code

message_name.xml Generate message templates

7. Choose OK.

PowerDesigner checks the model (if selected). If an error is found, generation stops, and anerror dialog shows what you must fix. If no errors are found, files are generated in the folderyou specified.

See also• Exporting a Single Message Definition on page 54

Developing a Publisher API StubDevelop a complete publisher from API stubs, or use the stubs as examples.

1. Generate the stub from the RAP Messages model.

2. Develop the main() method.

3. Develop the publish_<msgName>_Message() method.

4. Generate additional stubs as needed.

5. Consolidate the main() method, all publish_<msgName>_Message() methods,and error handling and logging for each method into a file that your feed handler codecalls.

See also• Generating a Publisher API Stub for a RAP Message on page 54

• Publisher API Stubs Example on page 59

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 55

main() method stubThe main() method calls pub_initialize(),publish_<msgname>_Message() which publishes the message, andpub_shutdown().

This example shows the main() method in the stub generated from the Bond Quote samplemessage definition.int main( int argc, char ** argv ) { PUB_STARTUP startup_settings; uint16_t errorCode;

// Set the startup_settings errorCode = pub_initialize( &startup_settings ); if( errorCode != ERR_NONE ) { // Add error handling code. }

errorCode = publish_Bond_Quote_Message(); if( errorCode != ERR_NONE ) { // Add error handling code. }

errorCode = pub_shutdown( true ); if( errorCode != ERR_NONE ) { // Add error handling code. } return 0;}

See also• pub_initialize on page 33

• pub_shutdown on page 37

• Developing the main() Method in a Stub on page 56

Developing the main() Method in a StubComplete the main() method by adding start-up and shutdown information and errorhandling.

1. Populate the PUB_STARTUP structure.

In the line below // Set the startup_settings, at &startup_settings,insert the information pub_initialize needs from PUB_STARTUP to initialize thepublisher. All fields in the PUB_STARTUP structure are required.

Your feed handler may also require other initialization outside the PUB_STARTUPstructure.

56 RAP - The Trading Edition

2. Add error handling where indicated in the stub comments.

At a minimum, the main() method needs error handling for initialization,publish_<msgName>_Message, and shutdown.

3. Add any other shutdown processing.

NextDevelop a publish_<msgName>_Message() method for each message, either fromstubs or by coding manually.

See also• main() method stub on page 56

• Initialization on page 27

• pub_initialize on page 33

• pub_shutdown on page 37

publish_<msgName>_Message() StubThe publish_<msgName>_Message method initializes the message withpub_beginMessage, calls various pub_set<type>Field methods to set field values,and sends or cancels the message.

The API method that publishes the message includes the message name in the formpublish_<msgName>_Message. Any characters that are not alphanumeric are changedto underscores. For example, publish_Bond_Quote_Message publishes the BondQuote message.

You must add error handling to each message processing loop.

Initializing FieldsThe publish_<msgName>_Message stub first defines thePUB_SEND_MESSAGE_CONTEXT structure with variables for each field in the message.This structure must be allocated before calling pub_beginMessage().

For example, the stub generated from the Bond Quote sample message definition begins with:uint16_t publish_Bond_Quote_Message(){ PUB_SEND_MESSAGE_CONTEXT ctx; uchar * Instrument; uint32_t Quote_Date; int32_t Quote_Sequence_Number; uint32_t Quote_Time_Date; uint32_t Quote_Time_Time; double Ask_Price; int32_t Ask_Size; double Bid_Price; int32_t Bid_Size;

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 57

double Yield; uint16_t errorCode;

Starting the MessageNext, the stub calls pub_beginMessage() to begin defining the message.

The stub calls pub_cancelMessage() in each message processing loop to execute if anerror is returned.

For example, the Bond Quote stub starts a new message as:// Parse your message here.

// Start a new message. errorCode = pub_beginMessage( 8, &ctx ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; }

Setting Field ValuesThe stub adds a pub_set<type>Field() method in a processing loop for each field fromthe message definition. You must add error handling.

If a field can be null, your code must check for null and call pub_setNullField. Calls topub_setNullField are commented out in the stub.

For decimal field types, the stub includes all potential API methods for processing the field,with all but pub_setDecimalField commented out. To use a different method, commentout pub_setDecimalField and uncomment the method you want. When choosing a setfield method, consider that supported datatypes may have performance or granularityimplications.

For example, the Bond Quote stub processes the Bid Price field as:// Add the Bid Price field to the message. errorCode = pub_setDecimalField( &ctx, "Bid Price", Bid_Price ); // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Bid Price", Bid_Price_Mantissa, Bid_Price_Exponent ); // errorCode = pub_setDecimalFieldFromString( &ctx, "Bid Price", Bid_Price_String ); // errorCode = pub_setNullField( &ctx, "Bid Price" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; }

Sending the MessageThe stub calls pub_sendMessage to send the message, or pub_cancelMessage uponerror.

58 RAP - The Trading Edition

See also• Example: Building a Market Data Message on page 51• Supported Datatypes for Message Flow on page 11• Developing with the publish_<msgName>_Message() Stub on page 59

Developing with the publish_<msgName>_Message() StubComplete publish_<msgName>_Message() in a generated stub by initializingvariables, adding error handling, and including the appropriate methods to set field values.

1. For all fields in the message, initialize variables (Instrument, Quote_Date, and so on) thatare to contain the data of the message.

These variables are required for the PUB_SEND_MESSAGE_CONTEXT structure.

2. Add error handling and logging where indicated in the stub comments.

3. For fields that can be null, test for NULL and either:

• Uncomment calls to pub_setNullField(), or,

• Call another pub_set<type>Field() method.

4. (Optional) For decimal fields, to use a different method, comment outpub_setDecimalField and uncomment the method you want.

5. Add other processing as needed.

See also• Example: Building a Market Data Message on page 51• publish_<msgName>_Message() Stub on page 57• Supported Datatypes for Message Flow on page 11

Publisher API Stubs ExampleThis example shows the complete stub generated from the Bond History message definition inthe sample RAP Messages model.

BOND_HISTORY.c Publisher API Stubtypedef enum {FALSE=0, TRUE} bool;#define true 1#define false 0

#include <stdint.h>#include "publisher_api.h"#include "publisher_errors.h"

uint16_t publish_Bond_Quote_Message();

int main( int argc, char ** argv ) { PUB_STARTUP startup_settings; uint16_t errorCode;

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 59

// Set the startup_settings errorCode = pub_initialize( &startup_settings ); if( errorCode != ERR_NONE ) { // Add error handling code. }

errorCode = publish_Bond_Quote_Message(); if( errorCode != ERR_NONE ) { // Add error handling code. }

errorCode = pub_shutdown( true ); if( errorCode != ERR_NONE ) { // Add error handling code. } return 0;}

uint16_t publish_Bond_Quote_Message(){ PUB_SEND_MESSAGE_CONTEXT ctx; uchar * Instrument; uint32_t Quote_Date; int32_t Quote_Sequence_Number; uint32_t Quote_Time_Date; uint32_t Quote_Time_Time; double Ask_Price; int32_t Ask_Size; double Bid_Price; int32_t Bid_Size; double Yield; uint16_t errorCode; // Parse your message here.

// Start a new message. errorCode = pub_beginMessage( 8, &ctx ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Instrument field to the message. errorCode = pub_setStringField( &ctx, "Instrument", Instrument ); // errorCode = pub_setNullField( &ctx, "Instrument" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Quote Date field to the message. errorCode = pub_setDateField( &ctx, "Quote Date", Quote_Date );

60 RAP - The Trading Edition

// errorCode = pub_setNullField( &ctx, "Quote Date" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Quote Sequence Number field to the message. errorCode = pub_setInt32Field( &ctx, "Quote Sequence Number", Quote_Sequence_Number ); // errorCode = pub_setNullField( &ctx, "Quote Sequence Number" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Quote Time field to the message. errorCode = pub_setDateTimeField( &ctx, "Quote Time", Quote_Time_Date, Quote_Time_Time ); // errorCode = pub_setNullField( &ctx, "Quote Time" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Ask Price field to the message. errorCode = pub_setDecimalField( &ctx, "Ask Price", Ask_Price ); // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Ask Price", Ask_Price_Mantissa, Ask_Price_Exponent ); // errorCode = pub_setDecimalFieldFromString( &ctx, "Ask Price", Ask_Price_String ); // errorCode = pub_setNullField( &ctx, "Ask Price" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Ask Size field to the message. errorCode = pub_setInt32Field( &ctx, "Ask Size", Ask_Size ); // errorCode = pub_setNullField( &ctx, "Ask Size" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Bid Price field to the message. errorCode = pub_setDecimalField( &ctx, "Bid Price", Bid_Price ); // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Bid Price", Bid_Price_Mantissa, Bid_Price_Exponent ); // errorCode = pub_setDecimalFieldFromString( &ctx, "Bid Price", Bid_Price_String ); // errorCode = pub_setNullField( &ctx, "Bid Price" );

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 61

if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Bid Size field to the message. errorCode = pub_setInt32Field( &ctx, "Bid Size", Bid_Size ); // errorCode = pub_setNullField( &ctx, "Bid Size" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Add the Yield field to the message. errorCode = pub_setDecimalField( &ctx, "Yield", Yield ); // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Yield", Yield_Mantissa, Yield_Exponent ); // errorCode = pub_setDecimalFieldFromString( &ctx, "Yield", Yield_String ); // errorCode = pub_setNullField( &ctx, "Yield" ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. return errorCode; } // Send the completed message. errorCode = pub_sendMessage( &ctx ); if( errorCode != ERR_NONE ) { pub_cancelMessage( &ctx ); // Add error handling code. } return errorCode;}

See also• Generating a Publisher API Stub for a RAP Message on page 54

• Developing a Publisher API Stub on page 55

Testing a Custom Feed HandlerTo test the feed handler and any associated message template and database schema changes,compile and link, configure publisher.xml and any custom configuration files, and usethe demo subscriber to test the full process.

This procedure tests message building and processing. It does not test performance, whichmust be done in your production environment.

1. Compiling a Feed Handler

62 RAP - The Trading Edition

Compile a custom feed handler against the Publisher API, using the shared library.

2. Configuring the Publisher API

Configure publisher.xml for your feed handler.

3. Creating a Custom Configuration File for the Feed Handler

Define a file to store additional configuration settings for your custom feed handler.

4. Creating a Startup Script

Create a shell script to start the feed handler.

5. Manually Registering a Publisher for Operations Console

Configure publishers so Operations Console can monitor and control them.

6. Testing with the Demo Subscriber

Run your feed handler with the demo subscriber to test that messages are processedcorrectly.

See also• Example: Building a Market Data Message on page 51• Feed Handler Shutdown on page 52• Application Development Using Publisher API Stubs on page 53• Debugging a Custom Feed Handler on page 73• Deploying a Custom Feed Handler on page 74

Compiling a Feed HandlerCompile a custom feed handler against the Publisher API, using the shared library.

PrerequisitesEnsure that your environment is configured correctly to invoke the compiler executable. Referto your compiler documentation for details.

Task

1. Set the library path environment variable to point to the publisher shared library: $RAP/PublisherAPI/lib/libpublisher.so.

Operating system Variable

AIX LIB_PATH

all others LD_LIBRARY_PATH

See the demo feed handler startup script for an example of how to set the library path.

2. Using the appropriate settings for your compiler, compile and link the feed handler againstthe Publisher API.

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 63

For an example, see the settings used to compile the demo feed handler in the suppliedbuild script, in $RAP/DemoFeedHandler/src/compile.sh.

If you use a custom logger or any other third party code, you must compile and link that aswell.

See also• Configuring the Publisher API on page 64

• Recompiling the Demo Feed Handler on page 80

• Compiler Options for the Publisher API Shared Library on page 80

Configuring the Publisher APIConfigure publisher.xml for your feed handler.

Calling pub_initialize() reads in and uses the settings in publisher.xml for all feedhandlers.

1. Review publisher.xml elements and the sample template.

2. Save publisher.xml in the /config folder of the directory that holds all files foryour feed handler.

For testing, you can copy the file from $RAP/DemoFeedHandler/config/publisher.xml from demo feed handler

3. Edit publisher.xml elements.

When starting with an existing file, at a minimum you must edit:• <AdminChannel> elements: <LocalInterface>, <AdminPort>• <ResendChannel> elements: <ResendPort>• One or more <DataStreamChannel> definitions including <ChannelName>,

<LocalInterface>, <IPAddress>, <Port>

See also• Compiling a Feed Handler on page 63

• Creating a Custom Configuration File for the Feed Handler on page 67

Publisher API XML Element DescriptionsUse the publisher.xml file to configure the publisher API.

Warning! Shut down the publisher API before modifying any of its configuration elements.

64 RAP - The Trading Edition

Table 8. Configurable elements of publisher.xml

Element Description

Publisher Root element for the configuration file.

Logger Contains settings for logging activities.

LogLevel The level of logging. Valid values are:

- Error: log only errors.

- Warning: log warnings in addition to errors.

- Info: log informational messages in addition to messages logged atthe warning level.

- Debug: log debugging messages in addition to messages logged atthe info level.

LogFile Name and location of the log file. The file name can be relative or afull path.

NumMessageBuffers Number of message buffers. One message buffer is required for eachmessage that is being simultaneously built. This setting can have avalue from 1 -- 65535, although the machine must have enoughmemory to hold the number of buffers specified.

NumPacketBuffers Maximum number of packets to cache to satisfy requests by a sub-scriber to resend a packet. The number of packets is cached per datastream channel. The setting can have a value from 1 -- 4294967296,although the machine must have enough memory to hold the numberof packets specified. The number of buffers is allocated on initiali-zation of the publisher.

MessageFlushInterval Interval, in seconds, during which a partially filled message buffermust be idle before being sent on the network. This setting can have avalue from 1 to 65535.

LatencyCheckInterval Number of seconds after which to do a latency check on a message.This setting can have a value from 1 to 65535.

AdminChannel Information about the administration channel. This channel acceptsrequests for version information, statistics, and shutdown.

LocalInterface Local interface that the publisher uses to monitor administrativerequests.

AdminPort Port number used by the UAF agent to communicate with the pub-lisher. The publisher listens for incoming administration requests onthis port.

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 65

Element Description

MaxConnections Determines the number of concurrent connections to the Admin-Channel. Defaults to 10. Value must be in the range of 1 to 65535.

ResendChannel Information about the resend channel. This channel listens for con-nections from subscribers, who open connections to publishers andissue requests to resend packets.

ResendPort Port number used by subscribers to request resends of dropped net-work packets, and to time network latency between publisher andsubscriber.

TimeToLive The limit on the number of routing devices a message may passthrough before expiring.

DataStreamChannelList A list of data stream channel definitions. There can be up to 255 datastream channels.

DataStreamChannel Contains information for one data stream channel. Each messagesent by the publisher is sent in a network packet buffer over one of thedefined channels. The publisher attempts to balance sending over allthe channels while the system is under load.

ChannelName Descriptive name for the channel, which is used to identify thechannel when logging.

LocalInterface IP address of a network interface on the local machine, which shouldbe used for sending data.

IPAddress UDP multicast address for sending the messages over the network.

Port Port over which messages are sent using UDP multicasting.

Publisher Sample TemplateA sample template of the publisher.xml configuration file.

<?xml version=”1.0” encoding=”UTF-8”?><Publisher> <Logger> <LogLevel>error</LogLevel> <LogFile>Publisher.log</LogFile></Logger> <NumMessageBuffers>10</NumMessageBuffers><NumPacketBuffers>250</NumPacketBuffers><MessageFlushInterval>1</MessageFlushInterval><LatencyCheckInterval>30</LatencyCheckInterval><AdminChannel>

<LocalInterface>Machinehostname</<LocalInterface> <AdminPort>10001</AdminPort>

66 RAP - The Trading Edition

<MaxConnections>10</MaxConnections></AdminChannel><ResendChannel> <ResendPort>10002</ResendPort></ResendChannel><TimeToLive>1</TimeToLive><DataStreamChannelList> <DataStreamChannel> <ChannelName>Channel 1</ChannelName> <LocalInterface>localhost</LocalInterface> <IPAddress>224.0.0.1</IPAddress> <Port>12001</Port> </DataStreamChannel> <DataStreamChannel> <ChannelName>Channel 2</ChannelName> <LocalInterface>localhost</LocalInterface> <IPAddress>224.0.0.2</IPAddress> <Port>12002</Port> </DataStreamChannel></DataStreamChannelList></Publisher>

Creating a Custom Configuration File for the Feed HandlerDefine a file to store additional configuration settings for your custom feed handler.

Prerequisites

Review publisher.xml to see what XML elements are there. Calling pub_initialize()reads in and uses the settings in publisher.xml for all feed handlers. Your custom fileonly needs to initialize custom code, if necessary, or to override settings inpublisher.xml.

While you can modify a custom configuration file at any time, it is a good practice is to create itand establish initial settings as you develop your feed handler. Manage your code to read theRAP configuration files, and add your own configuration files if needed.

Task

1. Define an XML file, properties file, or other source to contain configuration settings foryour feed handler.

Defining configuration settings in a separate file means that you do not need to recompilecode if settings change.

For custom feed handler configuration settings, you do not need to use a file that referencesXML elements as in publisher.xml.

2. Set XML elements or properties as needed for your publisher and environment.

Your file should specify sources for feeds, log files, and other information needed toassociate your publisher with the rest of the data flow in the system. It does not mirrorpublisher.xml

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 67

For examples, see the additional configuration settings for the FAST feed handler infastfeedhandler.xml.

3. Initialize the configuration file in a method you define in your publisher and ensure thatyour code parses the settings in your configuration file.

NextTo manage your feed handler from the OpsConsole, configure agent-plugin.xml,register the agent, and set required environment variables. You need to configure values for thepublisher host name and administration port, start command, component display names, andlog file.

See also• Configuring the Publisher API on page 64• Creating a Startup Script on page 68

Creating a Startup ScriptCreate a shell script to start the feed handler.

Use the demofeedhandler.sh or fastfeedhandler.sh script as an example.

1. Set the library path environment variable to point to the publisher shared library: $RAP/PublisherAPI/lib/libpublisher.so.

Operating system Variable

AIX LIB_PATH

all others LD_LIBRARY_PATH

See the demo feed handler startup script for an example of how to set the library path.

2. Set and export RAP_LOCALE to the locale to be used in resource bundles for logging:

• en_US (default for demo and FAST feed handlers)

• Other locale in the form cc_LC , where cc is the two-digit country code, and LC isthe two-digit language code

For example, for Japanese resource bundles, set:RAP_LOCALE=ja_JPexport RAP_LOCALE

3. (Optional) Include any other startup actions.

4. Invoke the executable.

See also• Creating a Custom Configuration File for the Feed Handler on page 67• Manually Registering a Publisher for Operations Console on page 69

68 RAP - The Trading Edition

Manually Registering a Publisher for Operations ConsoleConfigure publishers so Operations Console can monitor and control them.

In a production environment, administrators configure publishers from the OpsConsole.

In a development environment, you can set up the OpsConsole and configure publishers fromthere, or configure publishers manually as described here.

See also• Creating a Startup Script on page 68• Testing with the Demo Subscriber on page 72

Configuring the Agent for a PublisherEnable communication between the agent and the publisher by configuring properties in theagent-plugin.xml file.

The agent-plugin.xml file is located in:

RAP_R41_Installdir/sybase/RAP/PublisherName/ua/plugins/com.sybase.rap.rapservice/agent-plugin.xml

Note: PublisherName is the publisher you are configuring. For example, if you areconfiguring the demo feed handler, the publisher name is DemoFeedHandler.

To enable communication between the agent and the publisher, configure values for:

• rap.service_host

• rap.service_port

• rap.service_startCommand

• rap.service_pluginsubtype

• rap.service_plugindisplayname

• rap.service_logFile

See also• Registering an Agent to the JINI Server on page 71• Configuring Multiple Publishers on page 71• Updating the Environment Variables for Custom Publishers on page 72

Configuring the Publisher Host Name and Administration PortUse the agent-plugin.xml file to configure the rap.service_host and rap.service_portvalues for a publisher.

In the agent-plugin.xml file, specify the host name of the machine on which thepublisher is running and the administration port of the publisher:

<set-property property="rap.service_host" value="hostname" />

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 69

<set-property property="rap.service_port"value="admin_port_value" />

Configuring the Start Command and Enabling the Stop Function for the PublisherUse the agent-plugin.xml file to configure the rap.service_startCommand value for apublisher.

Specify the location of the script that starts the publisher:

<set-property property="rap.service_startCommand"value="RAP_R41_Installdir/sybase/RAP/PublisherName/bin/publishername.sh" />

Note: "publishername.sh" is the script for the publisher you are configuring. For example, ifyou are configuring the demo feed handler, the script name is demofeedhandler.sh.

Specify a fully qualified path rather than a relative path for the location of the script.

Ensure that the administration port value is configured properly in the agent-plugin.xml file to enable the stop function.

Configuring Component Display NamesUse the agent-plugin.xml file to configure the rap.service_pluginsubtype andrap.service_plugindisplayname values for a publisher.

In the agent-plugin.xml file, specify how the publisher subtype name and publisherdisplay name appear on Operations Console:

<set-property property="rap.service_pluginsubtype"value="SubtypeName"/>

<set-property property="rap.service_plugindisplayname"value="DisplayName"/>

Note: The publisher display name appears in parentheses beside the publisher subtype nameon the in the System View and Component View in the Operations Console, for example,Demo Feed Handler (DFH1).

Configuring the Log FileUse the agent-plugin.xml file to configure the rap.service_logFile value for a publisher.

Do this for a custom feed handler that uses a UAF agent. For the demo feed handler and FASTfeed handler, this value is set during installation.

In agent-plugin.xml, specify the location of the log file your custom feed handlergenerates:

set-property property="rap.service_logFile"value="log_file_full_path"

70 RAP - The Trading Edition

Specify a fully qualified path rather than a relative path.

For example:set-property property="rap.service_logFile" value="RAP_R41_Installdir/sybase/RAP/my_publisher/my_log_file" />

In the OpsConsole, when a user selects View Log for this publisher, the specified log fileappears.

Registering an Agent to the JINI ServerConfigure the specified property within the service-config.xml file to register theagent to the JINI server so Operations Console can display the agent on the monitor page.

The service-config.xml file is located in:

ComponentName/ua/services/Discovery/service-config.xml

1. To register the agent with the JINI server, specify the host name of the machine thepublisher is running on:<set-property property="host" value="hostname" />

2. After the agent is configured and registered, start the agent before testing with theOpsConsole.

See also• Configuring the Agent for a Publisher on page 69• Configuring Multiple Publishers on page 71• Updating the Environment Variables for Custom Publishers on page 72

Configuring Multiple PublishersTo configure multiple publishers on the same machine use the service-config.xmlfile.

Update the port value only when there are multiple publishers on the same machine. If thepublishers are running on separate machines, you need not update this value in theservice-config.xml file.

The service-config.xml file is in ComponentName/ua/services/RMI/service-config.xml

To configure multiple publishers on the same machine, specify the administration port of thepublisher:

<set-property property="port" value="portvalue" />

See also• Configuring the Agent for a Publisher on page 69• Registering an Agent to the JINI Server on page 71• Updating the Environment Variables for Custom Publishers on page 72

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 71

Updating the Environment Variables for Custom PublishersUpdate the environment variables in the myenv file for each publisher you create.

The myenv file is located in:

ComponentName/ua/bin/myenv

Within the myenv file, modify the environment variables in this line based on yourcustomizations:

SYBASE_UA=directory_of_UAF_agent/ua

See also• Configuring the Agent for a Publisher on page 69

• Registering an Agent to the JINI Server on page 71

• Configuring Multiple Publishers on page 71

Testing with the Demo SubscriberRun your feed handler with the demo subscriber to test that messages are processed correctly.

Prerequisites(Recommended) Set up your feed handler to run from the OpsConsole.

The demo subscriber writes binary output to a set of files. While you can examine these filedirectly, it is easier to use the OpsConsole to test that the subscriber is receiving data correctly.

Task

1. If your publisher is configured for the OpsConsole:

a) From the OpsConsole, view statistics for messages sent by the custom feed handler,and for messages received by the subscriber.

b) Compare the results.They should be the same, especially for a short run.

2. To look at data to ensure that it arrived correctly for a custom message type:

a) Define it for RAPCache and RAPStore in the message template.b) Ensure that the subscriber has the same template.c) Ensure that RAPCache and RAPStore data stores have the same table as in the template

to store the data, and that it is defined correctly.

3. From the OpsConsole, start RAPCache and RAPStore, and start your feed handler.

4. Use View Statistics in the Monitor to see how much data is received and loaded.

• If data is not being loaded at all, examine log files.

72 RAP - The Trading Edition

• If data is being loaded but is not what is expected, there is probably a problem with theset field method.

For example, date formatting or time formatting may be read in one way, but not sent to thesubscriber in the way that RAP requires. The feed handler must interpret data in a way thatRAP expects.

5. If data does not match what you expect, try either:

• Running a debugger• Writing log statements

See also• Manually Registering a Publisher for Operations Console on page 69

Demo SubscriberDemo subscriber demonstrates, along with the demo feed handler, how messages flowthrough RAP.

Demo subscriber receives messages from publishers and, depending on your configuration,either writes the messages to a file or discards them. The demo subscriber is not required in aproduction environment.

The demo subscriber receives messages from publishers on multiple data streams.

Each data stream listens for packets on one User Datagram Protocol (UDP) broadcast channel.When a packet arrives, the demo subscriber will either write the messages to a file or discardthe messages, depending on how the demo subscriber is configured.

Debugging a Custom Feed HandlerRun a debug-enabled compilation by accessing the debug library, where values of parameterscan be viewed, before starting a custom feed handler.

The debug library is built from the same objects as the production library, but uses a differentbuild process. Performance may decrease slightly when using the debug library, but this doesnot affect production builds.

1. Change LD_LIBRARY_PATH , or LIBPATH on AIX, to point to the debug publisherlibrary.

The debug library is in the debuglib folder in the same parent directory as theproduction library.

2. Compile your custom feed handler with debug information enabled, by calling:

./compile.sh –d

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 73

The –d flag instructs the compile script library to build a debug version, and to compileand link against the debug shared library rather than the production shared library.

3. Run the custom feed handler in a debugger.

See also• Testing a Custom Feed Handler on page 62

• Compiler Options for the Publisher API Shared Library on page 80

Deploying a Custom Feed HandlerMove custom feed handlers to your production environment by installing or updating.

• To move a new feed handler to a new or existing production environment, use the installer:

a) Install the publisher API in the production environment.b) Use the custom installer to complete the installation.

Specify settings for your feed handler in the Publisher API configuration dialogs.c) Copy the binary into the folder for the feed handler.d) Configure the agent to start the feed handler.e) Start the agent.f) Start the feed handler from the OpsConsole.

Note: If you want to add a new feed handler to an existing environment, Sybaserecommends using the installer to install the Publisher API in the directory where the newfeed handler should reside. Using the installer rather than just copying files has thesebenefits:• Installer prompts for configuration file settings. Using the installer ensures that your

publisher.xml settings correctly match settings entered during installation, andused by various components.

• Installer creates a directory for the agent and does most of its configuration, again fromvalues entered into the installer. All you need to do is specify the command to start thefeed handler from the agent.

• To update an existing feed handler:

a) From the OpsConsole, shut down the running feed handler.b) Update the binary for the feed handler.c) Use the OpsConsole to configure the publisher, and add or edit data stream channels.d) Start the feed handler from the OpsConsole.

See also• Example: Building a Market Data Message on page 51

• Feed Handler Shutdown on page 52

74 RAP - The Trading Edition

• Application Development Using Publisher API Stubs on page 53

• Testing a Custom Feed Handler on page 62

• Debugging a Custom Feed Handler on page 73

Configuring a Feed Handler for Other LanguagesEnsure that the sample API works correctly for your locale when using handlers that have beenbuilt from RAP publisher APIs.

1. Generate ja_JP.properties files in the appropriate format:

Component type Generated format

C++ based components (publishers, subscribers) UTF8

Java based components (OpsConsole, UAF agents) ASCII

2. Create an environment variable RAP_LOCALE=<locale>, where <locale> is ja_JP oren_US.

3. Create a directory $PublisherDir/lang, where $PublisherDir is thedirectory of your sample.

4. Copy files into $PublisherDir/lang, according to your RAP_LOCALE value:

RAP_LOCALEvalue

Files to copy into /lang

ja_JP • publisher_ja_JP.properties• templateprocessor_ja_JP.properties• util_ja_JP.properties

en_US • publisher_en_US.properties• templateprocessor_en_US.properties• util_en_US. properties

Note: You can find the en_US properties files under any of the other handler orsubscriber directories (for example, FASTFeedHandler/lang)

Configuring Subscribers for a Feed HandlerConfigure subscribers to receive messages from the custom feed handler.

PrerequisitesConfigure publishers first.

The easiest way to configure the production environment is from its OpsConsole. SeeOperations Console Users Guide > System Configuration >Configuring Components >Configuring a Subscriber.

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 75

To configure subscribers manually, see Installation and Configuration Guide > ConfigurationFiles and related topics for each type of subscriber.

Task

1. Configure any new RAPCache and RAPStore subscribers, either:

Method Action

From OpsConsole Edit the RAPCache and RAPStore subscribers

Edit configurationfiles

In $RAP/RAPCacheSubscriber/config, edit

rapcache.xml and opensubscriber.xml

In $RAP/RAPStoreSubscriber/config, edit

rapstore.xml and opensubscriber.xml

2. Add any new data stream channels to the subscriber, either:

Method Action

From OpsConsole Add data stream channels for the RAPCache and RAPStoresubscribers

Edit configurationfiles

In both $RAP/RAPCacheSubscriber/config and

$RAP/RAPStoreSubscriber/config, edit elements in

<DataStreamChannelList> in opensubscriber.xml.

3. Register the publisher for each subscriber.

Method Action

From OpsConsole Register Publisher for the RAPCache and RAPStore subscribers.

Edit configurationfiles

In both $RAP/RAPCacheSubscriber/config and

$RAP/RAPStoreSubscriber/config, edit elements in

<PublisherList> in opensubscriber.xml.

4. (Optional) Configure message filtering by editing messagefilter.xml in both$RAP/RAPCacheSubscriber/config, and $RAP/RAPStoreSubscriber/config.

Message filtering values must be identical for both the RAPCache and RAPStore.

For more information, see Message Filtering in Installation and Configuration Guide.

76 RAP - The Trading Edition

Tuning PerformanceOptimize performance in your application, and by setting configuration options.

Plan and test for optimal message transfer, including latency, and for optimal messageloading.

1. Review performance considerations in Performance and Tuning .

2. During development, pay attention to message buffering and logging design.

3. During testing, work with system administrators or others to ensure that configurableoptions are set to maximize performance.

Administrators may need to further adjust performance of production systems.

CHAPTER 4: Developing a Custom Feed Handler

Developers Guide 77

78 RAP - The Trading Edition

CHAPTER 5 Demo Feed Handler

The demo feed handler reads comma-delimited market data from a demo file and utilizes thePublisher API to send messages to a subscriber.

This component is intended to help developers become familiar with the Publisher API anddemonstrate network message flow.

Each line in the csv file contains one STOCK_QUOTE message. The csv file containing thesample data is located in:

<RAP_Installdir>/DemoFeedHandler/marketdata/messageformat/STOCK_QUOTE.csv

Running the Demo Feed Handler from the Command LineRun the demo feed handler from the command line.

The demo feed handler accepts command line parameters specifying the comma-delimitedmessage file, number of messages to send, and maximum messages to send per second.

Note: Although RAP includes STOCK_QUOTE.csv that you can use as a test message filefor demo feed handler, any .csv file that contains Stock Quote messages will work.

1. (Optional) Modify the demofeedhandler.sh script to start the demo feed handlerwith other settings.

2. Run the demo feed handler from the command line using:demofeedhandler -m messageFile -n numMessages -s maximum_messages_per_second

• Include the full path and file name of the demo data file as the messageFile argument.• Use a positive integer (any number from 1 to over 4 billion) as the numMessages

argument to process a specific number of messages. Specify -1 to continuously loopthrough the file until you manually stop it.

• -s maximum_messages_per_second is an optional switch that allows you tosimulate various scenarios. If you do not include this parameter, messages are sent atthe maximum possible speed.

For example, to start the demo feed handler with unlimited messages, and a throttle of300,000 messages per second, enter:

demofeedhandler -m messageFile -n -1 -s 300000

Developers Guide 79

Recompiling the Demo Feed HandlerUse the compile.sh build script to compile the demo feed handler.

PrerequisitesEnsure that your environment is configured correctly to invoke the compiler executable. Referto your compiler documentation for further details.

TaskEnter the compile command:

Compile type Command

Standard ./compile.sh

Debug enabled ./compile.sh -d

See also• Compiling a Feed Handler on page 63

• Compiler Options for the Publisher API Shared Library on page 80

Compiler Options for the Publisher API Shared LibraryThe compile.sh build script for the demo feed handler uses the compiler and link optionsin the table. You can also use these as examples when compiling a custom feed handler, but arenot required to use the listed compilers or settings.

The following tables list options for a production build. When compiling a debug build, addthe -g option to the listed production options.

RHEL/AMD compiler option for publisher APIs

Supported compiler gcc version 3.4.6.20060404 (Red Hat 3.4.6-9)

Compiler option -c -Wall -Werror -fPIC -D__STDC_LIMIT_MACROS=true -m64 -O3

Link option -Wall -Werror -fPIC -lpthread -ldl -O3 -lpublisher

Solaris SPARC compiler option for publisher APIs

Supported compiler CC: Sun C++ 5.8 2005/10/13

80 RAP - The Trading Edition

Compiler option -c -errtags=yes -KPIC -xO4 -xarch=v9

Link option -KPIC -lpthread -ldl -lsocket -lnsl -lrt -xO4 -xarch=v9

Solaris AMD compiler options for publisher APIsThe Solaris AMD operating system provides two supported compilers with separate compilerand link options.

Supported compiler CC: Sun C++ 5.8 2005/10/13

Compiler option c -errtags=yes -KPIC -xO4 -xarch=amd64 -xmodel=medium

Link option -KPIC -lpthread -ldl -lsocket -lnsl -lrt -xO4 -xarch=amd64 -xmo-del=medium

Supported compiler gcc version 3.4.6.20060404

Compiler option -fPIC -D__STDC_LIMIT_MACROS=true -m64

Link option -KPIC -lpthread -ldl -lsocket -lnsl -lrt

AIX compiler options for publisher APIsThe AIX operating system provides two supported compilers with separate compiler and linkoptions.

Supported compiler IBM® XL C/C++ Enterprise Edition V10.1 for AIX®

Compiler option -c -D__IBM_FAST_VECTOR -qpic=large -qhalt=i -qflag=w:w -q64 -qeh=v6 -O3 -qstrict -qtune=balanced -qhot

Link option -ldl -lpthread -qpic=large -q64 -qhalt=i -qflag=w:w -qeh=v6 -brtl -O3 -qstrict -qtune=balanced -qhot

Supported compiler gcc version 3.4.6.20060404

Compiler option -fPIC -D__STDC_LIMIT_MACROS=true -m64

Link option -KPIC -lpthread -ldl -lsocket -lnsl -lrt

See also• Compiling a Feed Handler on page 63

• Recompiling the Demo Feed Handler on page 80

• Testing a Custom Feed Handler on page 62

• Debugging a Custom Feed Handler on page 73

CHAPTER 5: Demo Feed Handler

Developers Guide 81

82 RAP - The Trading Edition

CHAPTER 6 FAST Feed Handler Customization

The FIX Adapted for Streaming (FAST) protocol is an emerging standard defined by the FIXProtocol, Ltd., as a method of compressing messages to be exchanged over a networkconnection.

The FAST feed handler connects directly to market data feeds, receives FAST-encodedmessages, decodes the data, and makes the decoded data available to the message handlerplug-in.

The FAST feed handler supports version 1.1 of the FAST protocol and conforms to Level 1 ofthe FAST Session Control Protocol (SCP) version 1.1.

Message Handler Plug-insA RAP message handler plug-in receives decoded FAST messages and maps them into theRAP publisher API.

Message handler plug-ins are shared libraries that are dynamically loaded at runtime. Theywork with the message handler, which is configured through the main configuration file(fastfeedhandler.xml).

See also• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

Developers Guide 83

Writing a Message Handler Plug-in for the FAST Feed HandlerThe demo message handler plug-in (ffhfixmsghandler.so) handles processing of select FIX4.4 message types (Advertisement, Mass Quote, Quote, SecurityStatus) defined in the FASTtemplates library (FIX44FASTLibrary.xml) that ships with the product. To process othermessage types, implement your own message handler plug-in.

Required functions and definitions:

• include/MessageHandlerAPI.h – Contains the function signatures for requiredfunctions, as well as for the two callback functions that can be used to tell FAST feedhandler to shut down and to release a ffh_fast_message.

• include/FASTMessage.h – Contains the definition for the ffh_fast_message and forother related C structs that are used to pass the contents of the decoded FAST message tothe message handler plug-in.

Warning! The plug-in cannot modify the contents of the ffh_fast_message or of any of itsmembers.

Implement the following functions for your message handler plug-in:

a) ffh_mh_init_function to create and initialize your message handler plug-in.b) ffh_mh_fini_function to release and clean up any resources used by your message

handler plug-in.c) ffh_mh_process_function to process a decoded FAST message by mapping it into the

publisher API.d) publisherShutdown, the callback required by the publisher API.

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

84 RAP - The Trading Edition

Writing a Message Handler Plug-in Initialize FunctionThe plug-in initialize function (ffh_mh_init_function) for the message handler preparesthe plug-in for use.

1. Initialize the RAP publisher API by invoking the pub_initialize() function.

Use the initParams argument to pass information needed to initialize the publisher API toyour plug-in (for example, the publisher configuration directory and the RDS templatesdirectory). InitParams are specified in the configuration file.

2. Set the PUB_STARTUP.callbacks.shutdown field to your publisherShutdown()function.

3. Create PUB_SEND_MESSAGE_CONTEXT, which will be shared by publisher APIcalls.

4. Perform any other initialization required by your plug-in.

For example, you can create an instance of a message handling class and store the pointerto this instance in the info->user_data member. You can use that pointer later toinvoke your class from the ffh_mh_fini_function and theffh_mh_process_function functions.

5. Store a global reference to the ffh_mh_info * info parameter for future access in yourpublisherShutdown() function.

Sample initialize functionextern "C“ int32_t initializeHandler( ffh_mh_info * info, ffh_init_param * initParams, int32_t initParamLen ){ info->user_data = new FIXMessageHandler(); return (( FIXMessageHandler* ) info->user_data)->initialize( info, initParams, initParamLen );}

int32_t FIXMessageHandler::initialize( ffh_mh_info * info, ffh_init_param * initParams, int32_t initParamLen ){ // initialize the logger by using external context log_init_from_context( info->loggerCtx );

// initialize Publisher API PUB_STARTUP startupSettings; startupSettings.component_subtype = "FAST Feed Handler"; startupSettings.strict_check = false; startupSettings.own_logger = true;

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 85

startupSettings.callbacks.shutdown = publisherShutdown;

for( int i = 0; i < initParamLen; i++ ) { if( strcmp( initParams[i].name, "PublisherConfigDir" ) == 0 ) { startupSettings.config_dir = initParams[i].value; } else if( strcmp( initParams[i].name, "RDSTemplateDir" ) == 0 ) { startupSettings.template_dir = initParams[i].value; } } int32_t error_code = pub_initialize( &startupSettings ); if( error_code != ERR_NONE ) { log_message( LOGGER_ERROR, error_code, “Initialization failed." ); return error_code; }

// create Publisher API message context _msg_ctx = new PUB_SEND_MESSAGE_CONTEXT();

// store the ffh_mh_info so that it can be used // by publisherShutdown() setHandlerInfo( info );

return ERR_NONE;}

where:

• ffh_mh_info * info – The info structure for calls to the message handler.• ff_mh_param *initParams – The initialization parameters for the handler.• ffh_initParamLen – The number of elements in the initParams array.

Returns:

int32_t 0 if the initialization succeeded; otherwise, a nonzero error code.

See also• Message Handler Plug-ins on page 83• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84• Arguments of the Message Handler Plug-in Initialize Function on page 87• Writing a Message Handler Plug-in Process Function on page 88• Arguments of the Message Handler Process Function on page 90• Writing a Message Handler Plug-in Finalize Function on page 90• Arguments of the Message Handler Finalize Function on page 91• Implementing the Shutdown Callback Method on page 92• C API Definitions of Function Signatures for Building a Message Handler on page 93• C API Definition of ffh_fast_message and its Related Structures on page 94

86 RAP - The Trading Edition

• FAST Templates on page 96

Arguments of the Message Handler Plug-in Initialize FunctionThe plug-in initialize function (ffh_mh_init_function) prepares the message handler plug-in for use.

The ffh_mh_info argument of the initialize function specifies the release_message andshutdown callbacks that should be used by the plug-in to release no longer neededffh_fast_message instances, or to request shutdown of the FAST feed handler.

ffh_mh_info->user_data can be used by the plug-in to store a pointer to an instance of itsmessage handler class for future reference.

The plug-in should save a reference to the ffh_mh_info argument so that it can use it in itsimplementation of the shutdown() function required by the publisher API. In that shutdown()function, the plug-in should invoke the shutdown callback specified in the ffh_mh_infoobject.

The ffh_init_param argument of the initialize function contains the values and the names ofthe initParam elements from the configuration file. It can be used to pass information neededto initialize the publisher API (for example, the publisher configuration directory and the RDStemplates directory).

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 87

Writing a Message Handler Plug-in Process FunctionThe message handler plug-in process function (ffh_mh_process_function) for themessage handler processes a decoded FAST message by mapping it into the publisher API.

Warning! Do not modify the contents of ffh_fast_message and its members in yourmessage-processing code.

1. Cast the event->info->user_data field to a pointer to an instance of your messagehandling class, if one was created during initialization.

2. If the event type is MHET_RECEIVE_MESSAGE, invoke the message processing methodson the message handler object and return the result.

3. In your message handler class, examine the contents of the event->message field, which isof type ffh_fast_message.

Based on the message type, use the publisher API to publish the message contents asdescribed in steps four and five.

4. Look for data required to create a RAP publisher message, then:

a) Invoke the publisher’s pub_beginMessage API.

b) Plug in the available data using pub_setXXXField API.

c) Call the publisher’s pub_sendMessage API .

d) Repeat for each publisher message contained within the ffh_fast_message.

5. Once the entire ffh_fast_message has been processed (or if the message was notprocessed because an error occurred), invoke the info->release_message callback,specifying the ffh_fast_message as the argument.

This notifies the FAST feed handler that it can release any resources associated with thegiven ffh_fast_message.

In the event of an error from the publisher API or missing or incorrect data, log the errorand call the publisher’s pub_cancelMessage API.

Sample process function

extern "C“ int32_t process( ffh_mh_event * event ){ return (( FIXMessageHandler* ) event->info->user_data)->receiveMessage( event->info, event->message );}

int32_t FIXMessageHandler::receiveMessage( ffh_mh_info * info, ffh_fast_message * fastMsg ){ uint32_t error_code = ERR_NONE;

88 RAP - The Trading Edition

// switch based on template id of incoming FAST message switch( fastMsg->template_id ) { case QUOTE_TEMPLATE_ID: // start creating a RDS Stock Quote message pub_beginMessage( STOCK_QUOTE_MSG, _msg_ctx ); // use Publisher API pub_setXXXField() calls // to populate its fields based on fastMsg // contents ... break; // handle other message types here case ... }

if( error_code != ERR_NONE ) { // error processing the FAST message, cancel it pub_cancelMessage( _msg_ctx ); } else { // successfully processed the FAST message, // publish it error_code = pub_sendMessage( _msg_ctx ); }

// release no longer needed FAST message info->release_message( info, fastMsg ); return error_code;}

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 89

Arguments of the Message Handler Process FunctionThe message handler plug-in process function (ffh_mh_process_function) for themessage handler processes a decoded FAST message by mapping it into the publisher API.

The ffh_mh_event argument of the process function contains a pointer to the sameffh_mh_info object that was passed to the plug-in initialization function, as well as a pointerto the ffh_fast_message object that holds contents of the decoded FAST message.

The plug-in should cast ffh_mh_event->info->user_data field as a pointer to an instance ofthe message handling class (if one was created during the initialization), then invoke itsmessage processing code.

In the message processing code, the plug-in maps the contents of the ffh_fast_message toRDS message(s) by invoking the publisher API.

Once the entire ffh_fast_message has been processed, the plug-in must invoke theffh_mh_info->release_message callback specifying ffh_fast_message as the argument.This notifies the FAST feed handler that it can release any resources associated with givenffh_fast_message.

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

Writing a Message Handler Plug-in Finalize FunctionThe message handler plug-in finalize function (ffh_mh_fini_function) for the messagehandler releases and cleans up any resources used by your message handler plug-in.

1. Cast the user_data field of the ffh_mh_info to a pointer to your message handling class, ifyou created one during the initialization.

90 RAP - The Trading Edition

2. Invoke the finalize method on the message handler object.

3. Delete the handler object and set the user_data pointer in ffh_mh_info to null.

Sample finalize function

extern "C" void finalizeHandler( ffh_mh_info * info ){ (( FIXMessageHandler*)info->user_data)->finalize(); delete ( FIXMessageHandler*)info->user_data; info->user_data = NULL;}

void FIXMessageHandler::finalize(){ // release Publisher API pub_shutdown( true );

// release other plug-in resources if( _msg_ctx != NULL ){ delete _msg_ctx; _msg_ctx = NULL; } _handlerInfo = NULL;}

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• C API Definition of ffh_fast_message and its Related Structures on page 94

• FAST Templates on page 96

Arguments of the Message Handler Finalize FunctionThe message handler plug-in finalize function (ffh_mh_fini_function) for the messagehandler releases and cleans up any resources used by your message handler plug-in.

The ffh_mh_info argument of the finalization function points to the same object that waspassed to the plug-in initialization function.

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 91

The plug-in should cast the ffh_mh_info->user_data field as a pointer to an instance of themessage handling class, if one was created during the initialization, invoke its cleanup code,delete the object, and then set it to null.

The callback method publisherShutdown is required by the publisher API.

See also• Message Handler Plug-ins on page 83• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84• Writing a Message Handler Plug-in Initialize Function on page 85• Arguments of the Message Handler Plug-in Initialize Function on page 87• Writing a Message Handler Plug-in Process Function on page 88• Arguments of the Message Handler Process Function on page 90• Writing a Message Handler Plug-in Finalize Function on page 90• Implementing the Shutdown Callback Method on page 92• C API Definitions of Function Signatures for Building a Message Handler on page 93• C API Definition of ffh_fast_message and its Related Structures on page 94• FAST Templates on page 96

Implementing the Shutdown Callback MethodpublisherShutdown is the callback method required by the publisher API to indicate that ashutdown has been requested.

Syntax: static void publisherShutdown();

If the ffh_mh_info structure is not null, invoke the structure’s session shutdown function,passing in the ffh_mh_info.

Sample publisherShutdown method

void publisherShutdown(){ ffh_mh_info * info = FIXMessageHandler::getHandlerInfo(); if( info != NULL ) { info->shutdown( info ); }}

See also• Message Handler Plug-ins on page 83• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84• Writing a Message Handler Plug-in Initialize Function on page 85• Arguments of the Message Handler Plug-in Initialize Function on page 87• Writing a Message Handler Plug-in Process Function on page 88

92 RAP - The Trading Edition

• Arguments of the Message Handler Process Function on page 90• Writing a Message Handler Plug-in Finalize Function on page 90• Arguments of the Message Handler Finalize Function on page 91• C API Definitions of Function Signatures for Building a Message Handler on page 93• C API Definition of ffh_fast_message and its Related Structures on page 94• FAST Templates on page 96

C API Definitions of Function Signatures for Building aMessage Handler

The C API, MessageHandlerAPI.h, defines the function signatures you must implementto build a message handler plug-in.

/* Initialization function */typedef int32_t (*ffh_mh_init_function)( ffh_mh_info *, /* handler info */ ffh_init_param *, /* array of init_param */ int32_t ); /* num ffhinit_param items */

/* Finalization function */typedef void (*ffh_mh_fini_fuction)( ffh_mh_info * );

/* Process Function */typedef int32_t (*ffh_mh_process_function)( ffh_mh_event * ); /* Return value from the above functions which return int32_t indicating success. Any other values indicate an error and are defined internally by the library. */#define FFH_MH_SUCESS 0

/* Callback functions */

typedef void (*ffh_mh_p_session_shutdown)( ffh_mh_info * );

typedef void (*ffh_mh_p_release_message)( ffh_mh_info *, ffh_fast_message * );

/* Data structures */

typedef struct { const char * name; const char *value;} ffh_init_param;

typedef enum ffh_mh_event_type {MHET_RECEIVE_MESSAGE = 0};

typedef struct { int16_t version; void * handlerID;

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 93

void * loggerID; ffh_mh_p_session_shutdown shutdown; ffh_mh_p_release_message release_message; void * user_data;} ffh_mh_info;

typedef struct { int16_t version; ffh_mh_event_type event; ffh_mh_info * info; ffh_fast_message * message; } ffh_mh_event;

See also• Message Handler Plug-ins on page 83• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84• Writing a Message Handler Plug-in Initialize Function on page 85• Arguments of the Message Handler Plug-in Initialize Function on page 87• Writing a Message Handler Plug-in Process Function on page 88• Arguments of the Message Handler Process Function on page 90• Writing a Message Handler Plug-in Finalize Function on page 90• Arguments of the Message Handler Finalize Function on page 91• Implementing the Shutdown Callback Method on page 92• C API Definition of ffh_fast_message and its Related Structures on page 94• FAST Templates on page 96

C API Definition of ffh_fast_message and its RelatedStructures

The C API, FASTMessage.h, defines ffh_fast_message and its related structures.ffh_fast_message and its related structures hold the contents of decoded FAST messages.

Warning! Do not modify the contents of the ffh_fast_message and its members in yourmessage-processing code.

When you are done with the ffh_fast_message, invoke the release_message callback onthe ffh_mh_info structure.

There will be a ffh_fast_field created for every field defined in the FAST templatecorresponding to the given ffh_fast_message. This includes any fields absent from theincoming stream. Those ffh_fast_fields have the value of their "present" member set tofalse.

The ascii_string, utf8_string and byte_vector members of theffh_vector_data are not '\0' terminated. You must use the length member of theffh_vector_data to determine their size.

94 RAP - The Trading Edition

typedef uint8_t byte;

typedef enum { FFT_GROUP = 1, FFT_SEQUENCE, FFT_INT32, FFT_UINT32, FFT_INT64, FFT_UINT64, FFT_DECIMAL, FFT_ASCII, FFT_UNICODE, FFT_BYTES} ffh_field_type;

typedef struct { const char * name_space; const char * name;} ffh_fast_name;

typedef struct { int64_t mantissa; int32_t exponent; } ffh_fast_decimal;

typedef struct { size_t length; union { char * ascii_string; byte * utf8_string; byte * byte_vector; };} ffh_vector_data;

typedef struct ffh_fast_field ffh_fast_field;

typedef struct { /* An array of fast_field pointers */ ffh_fast_field ** fields; /* The number of entries in the above array */ size_t field_count;}ffh_fast_group;

typedef struct { ffh_fast_name template_name; uint64_t template_id; ffh_fast_group data;} ffh_fast_message;

typedef struct { size_t length; ffh_fast_group * elements; /* Array of groups */ } ffh_fast_sequence;

struct ffh_fast_field { ffh_fast_name name;

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 95

ffh_field_type type; bool present; union { int32_t int32; uint32_t uint32; int64_t int64; uint64_t uint64; ffh_fast_decimal decimal; ffh_fast_sequence sequence; ffh_fast_group group; ffh_vector_data vector; };};

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

• FAST Templates on page 96

FAST TemplatesFAST feed handler comes with a FAST template library for four FIX 4.4 market datamessages: Advertisement, Quote, MassQuote, and SecurityStatus.

The FAST templates come with all fields defined for those message types in the FIX 4.4 specs,including the standard header and trailer. Only a few operators are specified in the templates;you can use additional operators as warranted.

Warning! Removing or adding new fields to the templates is likely to disable the RAPmessage handler plug-in.

The FAST templates and related schema files are installed in the folder $RAP/FASTFeedHandler/fasttemplates.

96 RAP - The Trading Edition

Table 9. FAST template installed files

File Description

FIX44FASTLibrary.xml FAST templates for select FIX 4.4 messages.

Warning! Changes to FIX44FASTLi-brary.xml might break the FIX message

handler plug-in (ffhfixmsghan-dler.so) which processes the decoded FAST

messages described in those templates.

scp-1.1-level-1.xml FAST template for the SCP 1.1 Reset message.

FASTSchema.xsd XSD schema, used to validate FAST templates.

Your FAST templates must adhere to this schemaas it is used while parsing the templates XML file.

scpschema.xsd SCP 1.1 "reset" attribute that is included by theFASTSchema.xsd. Your FAST templates can in-clude the SCP 1.1 "reset" attribute.

A FAST template for the SCP 1.1 Reset messageis also provided in /fasttemplates/scp-1.1-level-1.xml. The FAST

specifications require each UDP packet to startwith a Reset message or with any other templatesthat have the reset property enabled.

None of the FAST templates for FIX messagesincluded with the FAST feed handler have thereset property enabled.

See also• Message Handler Plug-ins on page 83

• Writing a Message Handler Plug-in for the FAST Feed Handler on page 84

• Writing a Message Handler Plug-in Initialize Function on page 85

• Arguments of the Message Handler Plug-in Initialize Function on page 87

• Writing a Message Handler Plug-in Process Function on page 88

• Arguments of the Message Handler Process Function on page 90

• Writing a Message Handler Plug-in Finalize Function on page 90

• Arguments of the Message Handler Finalize Function on page 91

• Implementing the Shutdown Callback Method on page 92

• C API Definitions of Function Signatures for Building a Message Handler on page 93

CHAPTER 6: FAST Feed Handler Customization

Developers Guide 97

• C API Definition of ffh_fast_message and its Related Structures on page 94

98 RAP - The Trading Edition

APPENDIX A FIX Message to Data Model Mappings

FIX messages map on to different RDS message types, such as stock, bond, mutual fund,option, and index instruments.

General Processing NotesInformation about general processing for FIX field names, field numbers, and allowed values.

The message mappings defined here use the FIX field names. For details on the actual fieldnumbers and allowed values, see the FIX protocol specification version 4.4 at http://fixprotocol.org/specifications/fix4.4fiximate/index.html.

Instrument BlocksInstrument blocks provide information about entities in the FIX messages.

Each supported FIX message type contains at least one instrument block that providesinformation about the entity for which data is present in the message. Some messages cancontain information about multiple instruments. In general, the Symbol or Security ID fieldsof the instrument block map on to the stock symbol of the corresponding RAP table, and this isused to automatically look up instrument IDs in the instrument table. The lookup is completedvia the RDS template mechanism.

Note: A default value for lookup table failures must be specified in the template.

Data Aggregation and Missing DataThe data in FIX messages can be unordered, and many FIX fields in a message are optional.The RDS format does not support optional values. You may want to change any or all of thesebehaviors before you invoke the publisher API to send data.

1. Iterate over the available message and fill in a data structure that represents your requireddata.

2. If, after processing, the FIX message does not contain sufficient data, log an error.

3. If the message contains enough data, call the publisher API to begin processing the correctRDS message, set the field data, and then send the message.

Note: Perform these steps on a per-instrument basis for FIX messages that supportmultiple instruments. For FIX messages that support multiple destination RDS messagesfor a single instrument, you may need to concurrently aggregate data for multiple RDSmessages, since the FIX data for the different RDS messages may be interleaved.

Developers Guide 99

Determining RDS Message Types Based on FIX MessagesRAP determines which type of RDS message to generate based on the type of instrumentbeing processed.

Some FIX messages apply to different instruments. Since RDS does not support optionalfields and not all of the FIX data mappings defined here contain all of the data to fully populatethe standard RDS messages, you must define RDS message types that are similar to the fullRDS messages, but have fields omitted.

Stock InstrumentsStock instruments are identified by field types and values within the field.

If the Product field is present in the Instrument block, and has the value 5 (EQUITY), theinstrument is a stock.

If Product is not present, but Security Type is, and has the value CS or PS (Common Stock orPreferred Stock), the instrument is a stock.

If neither Product nor Security Type are present, but the CFICode field is, and the firstcharacter of the field is E (for Equity) and the second letter is one of S, P, R, C, F, or V, theinstrument is a stock.

Otherwise, this is not a stock.

Note: RAP - The Trading Edition does not support securities that offer multi-leg options.

See CFICode values at http://www.iso.org/iso/catalogue_detail?csnumber=32835 for fulldocumentation.

Bond InstrumentsBond instruments are identified by the presence of a CFICode and two characters within thefield.

If the CFICode is present and the first character of the field is D (for Debt) and the secondcharacter is B (for Bond), the instrument is a bond.

Mutual Fund InstrumentsMutual fund instruments are identified by field types and values within the field.

If the Security Type is present and has the value of MF, the instrument is a mutual fund.

If the Security Type is not present, but the CFICode is, and the first character of the field is E(for Equity) and the second is U (Units), then the instrument is a mutual fund.

Option InstrumentsOption instruments are identified by field types and values within the field.

If the Security Type is present and has the value of OPT, the instrument is an option.

100 RAP - The Trading Edition

If the Security Type is not present, but the CFICode is, and the first character of the field is O(for Options), the instrument is an option.

Index InstrumentsIndex instruments are identified by field types and values within the field.

If the Product field of the Instrument block is present and has the value 7 (INDEX), theinstrument is an index.

If Product is not present, but Security Type is, and has the value INDEX, the instrument is anindex.

If neither Product nor Security Type are present, but the CFICode field is, and the firstcharacter of the field is M (for Miscellaneous), and the second letter is one of R (forReferential) and the third letter is I (for Indices), the instrument is an index.

Otherwise, this is not an index.

Advertisement FIX MessageFIX Advertisement messages map into four different RDS message types: Stock Trade,Mutual Fund History, Bond Trade, and Option Trade.

Stock Trade RDS MappingIf the TradeDate Field in the FIX message is a stock instrument, data in the FIX message mapsinto a Stock Trade RDS message, which is stored in the STOCK_TRADE table.

Table 10. STOCK_TRADE conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TradeDate TRADE_DATE

AdvID TRADE_SEQ_NBR

SecurityID/Symbol TRADING_SYMBOL

TransactTime TRADE_TIME

Price TRADE_PRICE

Quantity TRADE_SIZE

APPENDIX A: FIX Message to Data Model Mappings

Developers Guide 101

Mutual Fund History RDS MappingIf the TradeDate Field in the FIX message is a mutual fund instrument, data in the FIXmessage maps into a Mutual Fund History RDS message, which is stored in theMUTL_FIND_HIST table.

Table 11. MUTL_FUND_HIST conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TradeDate or currentdate

TRADE_DATE

SecurityID/Symbol TRADING_SYMBOL

Price PRICE

Bond Trade RDS MappingIf the TradeDate Field in the FIX message is a bond instrument, data in the FIX message mapsinto a Bond Trade RDS message, and is stored in the BOND_TRADE table..

Table 12. BOND_TRADE conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TradeDate TRADE_DATE

AdvID TRADE_SEQ_NBR

Yield TRADE_YIELD

TransactTime TRADE_TIME

Price TRADE_PRICE

Quantity TRADE_SIZE

Option Trade RDS MappingIf the TradeDate Field in the FIX message is an option instrument, data in the FIX messagemaps into an Option Trade RDS message, and is stored in the OPTION_TRADE table.

Table 13. OPTION_TRADE conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

102 RAP - The Trading Edition

FIX message field Table column

TradeDate TRADE_DATE

AdvID TRADE_SEQ_NBR

There is no OPEN_IN-TEREST in Advertise-ment

OPEN_INTEREST

TransactTime TRADE_TIME

Price TRADE_PRICE

Quantity TRADE_SIZE

Mass Quote FIX MessageFIX Mass Quote messages map into two RDS message types: Stock Quote and Bond Quote.

Mass Quote FIX messages contain repeating groups for instruments. For each repeatedgrouping that instrument can have a repeated block of quote data. Each one of these quotes isprocessed in the same manner that a Quote FIX message is processed.

Stock Quote RDS MappingIf the instrument is a stock, data in the FIX message maps into a Stock Quote RDS message,and is stored in the STOCK_QUOTE table.

Table 14. STOCK_QUOTE conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TransactTime QUOTE_DATE

QuoteID QUOTE_SEQ_NBR

SecurityID/Symbol TRADING_SYMBOL

TransactTime QUOTE_TIME

OfferPx ASK_PRICE

OfferSize ASK_SIZE

BidPx BID_PRICE

BidSize BID_SIZE

APPENDIX A: FIX Message to Data Model Mappings

Developers Guide 103

Bond Quote RDS MappingIf the instrument is a bond, data in the FIX message maps into a Bond Quote RDS message,and is stored in the BOND_QUOTE table.

Table 15. BOND_QUOTE conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TransactTime QUOTE_DATE

QuoteID QUOTE_SEQ_NBR

Yield YIELD

TransactTime QUOTE_TIME

OfferPx ASK_PRICE

OfferSize ASK_SIZE

BidPx BID_PRICE

BidSize BID_SIZE

Security Status FIX MessageThe FIX Security Status messages map into Stock History RDS messages.

Stock History RDS MappingIf the instrument is a stock, data in the FIX message maps into a Stock History RDS message,and is stored in the STOCK_HISTORY table.

Table 16. STOCK_HISTORY conditions

FIX message field Table column

SecurityID/Symbol INSTRUMENT_ID

TransactTime TRADE_DATE

SecurityID/Symbol TRADING_SYMBOL

LowPx LOW_PRICE

HighPx HIGH_PRICE

BuyVolume/SellVo-lume

VOLUME

104 RAP - The Trading Edition

IndexAAdaptive Server Enterprise database 2advertisement FIX messages 101

bond trade RDS mapping 102mutual fund history RDS mapping 102option trade RDS mapping 102stock trade RDS mapping 101

agentconfiguration 52, 69–71

agent plug-ins 2API

functions 39publisher data structures 31publisher methods 32

architecture(diagram) 2demo subscriber 73

argumentsfinalize function 91initialize function 87process function 90

Bbit datatypes 12bond

instruments 100quote RDS mapping 104trade RDS mapping 102

build scriptcompile.sh 80demo feed handler 80

buildinga market data message 51a message handler plug-in 93

building messagesprocessing phase 5

CC API definitions of function signatures 93callbacks

Publisher API 31char datatypes 12

characterdatatypes 15

code samplesBOND_HISTORY.c 59Publisher API stub 59

codeserrors 30

columnadding 25

command linerunning the demo feed handler 79

commandspublisher start command 52, 70

compiler optionspublisher shared library 80

compilingfeed handlers 63

compiling the demo feed handler 80configuration file

custom feed handlers 67publisher 66

configuration files (by component)publisher API 64

configuration files (by file name)publisher.xml 64

configuringa publisher 69–71an agent 69–71publisher.xml 64subscribers 75the publisher start command 70

conversionsautomatic datatype 10date 13integer 13numeric 14signed integers 13time 13unsigned integers 13

custom feed handlerdeveloping 49initializing 49processing messages 49shutting down 49testing 62

Index

Developers Guide 105

custom feed handlerscreating a configuration file 67deploying 74testing with the demo subscriber 72

customizationscenarios 6

Ddata aggregation 99

FIX messages 99data model mappings

advertisement FIX messages 101mass quote FIX messages 103security status FIX messages 104

data storesRAPCache database 4RAPStore database 4

data stream handler 4data structures

defining 49Publisher API 31

data transfersupported datatypes 15

databasecustomizing 9modifying 24naming restrictions 24

databasesAdaptive Server Enterprise 2IQ 2Sybase IQ 2

datatype conversions 10automatic 10date 13integer 13numeric 14signed integers 13time 13unsigned integers 13

datatypesbit 12char 12character 15date 13, 15datetime 13, 15decimal 15float 12integer 15

large object binary 12money 12numeric 15RDS 11SQL 11supported for data transfer 15text 12time 13unsupported 12varchar 12

datedatatypes 15

date conversions 13date datatypes 13datetime

datatypes 15datetime datatypes 13debug publisher library

compiling with 73debugging

custom feed handlers 73decimal

datatypes 15definitions

function signatures 93demo feed handler

build script 80compile.sh 80compiling 80overview 79running from the command line 79

demo message handler plug-in 84demo subscriber

architecture 73testing custom feed handlers 72

derived dataoverview 5transfer and truncation 5

See also lookup tablesdescriptions of elements

RDS sample template 17determining RDS message types 100

FIX messages 100development environment 2development scenarios 6

Eelement descriptions

Index

106 RAP - The Trading Edition

RDS sample template 17environment for sample API 75error codes 30error handling

in Publisher API stub 57examples

Publisher API stub 59Publisher API stubs 55

exportingmessage definition 54

extended generationmessages 54Publisher API stub code 54

FFAST feed handler 83

overview 83FAST protocol 83FAST templates 96FASTMessage.h 94feed handler

configuring log file 70customizing 49initializing 49processing messages 49shutting down 49

feed handlers 32building a market data message 51compiling 63debugging 73demo feed handler 79overview 3shutting down 52

ffh_fast_message 94ffh_mh_fini_function 90, 91ffh_mh_init_function 85, 87ffh_mh_process_function 88, 90finalize function

arguments 91message handler plug-in 90writing a finalize function 90

FIXdata model mappings 99field names 99field numbers 99

FIX Adapted for Streaming Feed Handler.See FAST feed handler

FIX Adapted for Streaming protocol.See FAST protocol

FIX data model mappings 100advertisement FIX messages 101mass quote FIX messages 103security status FIX messages 104

FIX message typesadvertisement 101mass quote 103security status 104

FIX messages 99allowed values 99data aggregation 99determining RDS message types 100instrument blocks 99missing data 99

float datatypes 12function

signature definitions 93stop function 52, 70

functionsAPI 39finalize 90initialize 85, 87process 88, 90pub_beginMessage 28SendMessage 28

Ggenerating

from RAP Message model 22from RAPCache model 23from RAPStore model 23Publisher API stub 54RAP message template 54RAP Message template 23RAPCache model 22RAPStore model 22

Iidentifying instruments

bond instruments 100index instruments 101mutual fund instruments 100option instruments 100stock instruments 100

impact analysisoverview 23

index instruments 101

Index

Developers Guide 107

initialization informationPublisher API 31

initialization methodPublisher API 27

initialize functionarguments 87message handler plug-in 85, 87writing 85

initializing the Publisher API 33instrument blocks 99

FIX messages 99instrument types

bond 100index 101mutual fund 100option 100stock 100

instruments.See instrument types

integerconversions 13datatypes 15signed 13unsigned 13

Llarge object binary datatypes 12library path

setting environment variable 63lineage analysis

overview 23loading messages

processing phase 5localized messages 46log file

configuring 70log levels 39log_close 42log_get_context 43log_get_filename 45log_hexdump 43log_init_from_context 42log_message 41log_open 39, 44logger.h 39logging 38, 39

buffering resource messages 46forcing resource messages 45

initialize resource 40localized messages 46log_close 42log_get_context 43log_get_filename 45log_hexdump 43log_init_from_context 42log_message 41log_message_force 44log_open 39overview 38resource messages 41

lookup tablesconvertibility 15

Mmain() method

in Publisher API stub 55, 56Publisher API stub 56

mappingsSee message mappings

mappings.See message mappings

market data messagesPublisher API 31

mass quote FIX messages 103bond quote RDS mapping 104stock quote RDS mapping 103

message definitionexporting 54generating a Publisher API stub 54generating a RAP message template 54RDS sample template 17

message definitionsexporting 21exporting selected messagess 54extended generation 54generating 21generating message templates 54generating stub code 54

message filteringconfiguring in messagefilter.xml 75

message handler plug-in finalize function 91arguments 91

message handler plug-in initialize function 85, 87arguments 87

message handler plug-in process function 88, 90arguments 90

Index

108 RAP - The Trading Edition

message handler plug-ins 83, 84finalize function 90, 91initialize function 85, 87process function 90writing 84

message mappingsbond trade RDS 102mutual fund history RDS 102option trade RDS 102RDS to SQL datatypes 11stock trade RDS 101

message modelingin PowerDesigner 21overview 21scenarios 20

message processingphases 5

message templatemodifying schema 24

message.xml filegenerating from message definition 21

MessageHandlerAPI.h 93messages

customizing 9customizing a message model 20generating stub code 53modeling in PowerDesigner 21publishing 59

messages modelexporting 54generating stub code 54

methodslog_close 42log_get_context 43log_get_filename 45log_get_rsrc_message 46log_hexdump 43log_init_from_context 42log_init_resource 40log_message 41log_message_force 44log_open 39log_rsrc_message 41log_rsrc_message_force 45pub_beginMessage 34pub_cancelMessage 35pub_flush 37pub_initialize 33pub_sendMessage 37

pub_setField 35pub_shutdown 37publisher API 32publisherShutdown 92

missing data 99FIX messages 99

modelsanalyzing impact of changes 23analyzing object lineage 23generating a RAP Messages model from a

physical model 23generating a RAPCache model 22generating a RAPStore model 22

money datatypes 12mutual fund

history RDS mapping 102instruments 100

Nnaming restrictions

RAPCache and RAPStore 24network layer 3numeric

conversions 14datatypes 15

Oopen subscriber 4Operations Console 71

configuration 69configuring 71overview 4setting display name properties 70

optioninstruments 100trade RDS mapping 102

overviewFAST feed handler 83feed handlers 3logging 38Operations Console 4Publisher API 27publishers 3RAP development 1, 2subscriber 4

Index

Developers Guide 109

Pperformance tuning

overview 77platform architecture 2plug-ins

message handler 83UAF 4

process functionarguments 90message handler plug-in 88writing 88

productiondeploying custom feed handlers 74

pub_beginMessage 34PUB_CALLBACKS

data structure for shutdown processing 49pub_cancelMessage 35pub_flush 37pub_initialize 33pub_initialize()

in main() method 56in Publisher API stub 56

PUB_SEND_MESSAGE_CONTEXTdata structure for message processing 49

pub_sendMessage 37pub_setField 35pub_shutdown 37pub_shutdown()

in main() method 56in Publisher API stub 56

PUB_STARTUPdata structure for initialization processing 49in Publisher API stub 56

publish_<msgName>_Message()in Publisher API stub 55, 57, 59

publish_Bond_Quote_Messagein Publisher API stub 56

publisherconfiguration 52, 69–72configuring the start command 52, 70overview 3stop function 52, 70

publisher API 3, 34, 35, 37, 51configuration file (publisher.xml) 64environment for sample API 75error codes 30locale 75message handler plug-in 83

methods 32process function 90RDS sample template 17sending messages 28

Publisher API 27callbacks 31data structures 31generating stub code 54initialization information 31initialization method 27initializing 33market data messages 31version constant 27

Publisher API data structures 31publisher API methods 32

pub_beginMessage 34pub_cancelMessage 35pub_flush 37pub_sendMessage 37pub_setField 35pub_shutdown 37publisherShutdown 92

Publisher API methodsinitialization 27pub_initialize 33

Publisher API stubdeveloping 55–57, 59error handling 56, 57, 59example 59generating from the Properties sheet 54main() method 56publish_<msgName>_Message() 57, 59

Publisher API stub codegenerating 54

Publisher API stubsoverview 53

publisher shared librarycompiler options 80link options 80

publisher.xml 64configuring 64custom feed handlers 67

publisherShutdown method 92publishing a message

in Publisher API stub 57, 59

RRAP

Index

110 RAP - The Trading Edition

development environment 2overview 1

RAP data stream templates.See RDS templates

RAP developmentoverview 1, 2

RAP message templatedeveloping 21exporting 21generating from message definition 21generating from the Properties sheet 54

RAP message templatesextended generation tool 54generating from message definitions 54

RAP Messages modelgenerating from a RAPCache model 22, 23generating from a RAPStore model 22, 23

RAPCache data stream handler 4RAPCache database 4RAPCache subscriber 10RAPStore data stream handler 4RAPStore database 4RAPStore subscriber 10RDS datatypes

message mappings 11RDS message format 3RDS message types 100RDS sample template 17

XML element descriptions 17RDS templates

location 10performance impact 10

RDS to SQL datatype mappings 11resource bundles

default location 47introduction 38, 47localizing 47

Ssample template

publisher 66RDS 17

schemacustomizing 9modifying 24naming restrictions 24

security status FIX messages 104stock history RDS mapping 104

sending messagesmarket data 37publisher API 28

shutting down a feed handler 52SQL datatypes

message mappings 11startup

creating shell script 68stock history RDS mapping 104stock instruments 100stock quote RDS mapping 103stock trade RDS mapping 101stub code

exporting 54generating 54generating from the Properties sheet 54overview 53Publisher API 53

subscriberinformation required 17overview 4

subscribersconfiguring 75demo subscriber 73

Sybase IQ database 2

Ttable

adding 24tables

lookup 15templates

FAST feed handler 96sample publisher template 66sample RDS 17

testingcustom feed handler 62

testing custom feed handlersdemo subscriber 72

text datatypes 12time conversions 13time datatypes 13transferring messages

processing phase 5truncation

derived data 5

Index

Developers Guide 111

UUAF 2

plug-ins 4Unified Agent Framework.

See UAFunsupported datatypes 12updating

environment variables 72

Vvarchar datatypes 12variables

environment variables 72version constant

initialization 27

Wwhite papers

high availability 2time series 2

writingfinalize function 90initialize function 85message handler plug-in 84process function 88

XXML element descriptions 17

RDS sample template 17XML file

custom feed handlers 67

Index

112 RAP - The Trading Edition