See: Description
Interface | Description |
---|---|
BlotterChannel | Deprecated |
BlotterEvent | Deprecated |
BlotterMessage | Deprecated |
BlotterTradeListener | Deprecated |
InvalidFieldsEvent |
An event raised when one or more of the fields sent in a client event are invalid.
|
InvalidTransitionEvent |
An event raised when a client event would trigger an invalid state transition on the trade model.
|
Leg |
Trades are comprised of one or more trade legs, each representing the exchange of a financial instrument and
the resultant cashflow.
|
LegAction |
The LegAction interface represents a change to the legs that make up a trade.
|
Trade |
A single Trade active in the system.
|
TradeChannel |
An open trade messaging communications channel with an end user.
|
TradeChannelListener |
Provides notifications relating to the
Trade lifecycle. |
TradeErrorEvent | |
TradeEvent |
A single event acting on a Trade.
|
TradeListener |
Used to receive TradeEvents from the system.
|
TradingApplicationListener |
Use the TradingApplicationListener interface to be notified of
TradeChannel and
BlotterChannel lifecycle events. |
Class | Description |
---|---|
TradingProvider |
All Trading DataSource applications must create an instance of this class.
|
Enum | Description |
---|---|
EventSource | |
LegAction.LegActionType |
An enumeration of possible actions that can be performed on a leg.
|
Exception | Description |
---|---|
BlotterClosedException | Deprecated |
InvalidFieldsException | |
TradeException |
Used for all errors raised by the Trading DataSource, or raised by user code that needs to notify the
Trading DataSource of an exception during a callback.
|
The Caplin Trading Integration API provides Java classes and interfaces that allow you to create Trading Adapters.
A Trading Adapter sits between Caplin Liberator and an external trading system, handling the trade messages that flow between Caplin Platform client applications and the trading system when an end-user trades.
The Trading Integration API is built on top of the
Caplin DataSource for Java API (package com.caplin.datasource
and its subpackages). It allows
Trading Adapters to communicate with Liberator using the
DataSource protocol, but without the need to write code at the DataSource
API level.
In this API documentation, a Trading Adaptor is sometimes referred to as a Trading DataSource application, or Trading DataSource, for convenience.
For additional information about how to use this API, see the document Trading 6.0: Integrating The Caplin Platform With A Trading System.
Note: Previous versions of this API were called the Caplin Xaqua Trading DataSource API.
The Caplin Trading Integration API is part of the Caplin Integration Suite Software Development Kit (SDK) and contains the following components:
Follow the links below for information about the Trading Integration API:
The following changes have been made with respect to the previous versions of this API (previously called "Caplin Xaqua Trading DataSource API").
The way in which you construct the main Trading Adapter objects has changed:
The TradingDataSource class is replaced by a new class called TradingProvider
.
The TradingProvider
uses a DataSource
instance,
which connects to Liberator and also sets up the necessary DataSource listeners
internally to handle the trade and blotter messaging.
This allows you to create a DataSource application that uses both the v5.x Trading Integration API for Java and the v5.x Permissioning Integration API for Java, so that the same application can act both as a Trading Adapter and a Permissioning Adapter.
The constructor of TradingProvider
takes just a
TradingApplicationListener
and a DataSource
,
and is therefore much simpler than the TradingDataSource
class
that it replaces.
ChannelListener
class is now called the TradeChannelListener
.
Configuration File
Configuration for the Trading Adapter can now be specified through the
DataSource
constructor of the DataSource for Java API, either by providing configuration
options in DataSource configuration (eg datasource.conf
), or passing a command option called
--trading-property-file
. The configuration file can specify trade models, subject patterns for
Trade Channels, Blotter Channels, and Blotter Channel items, and the location pattern where the audit
log will be written. For a more detailed description, see Configuration
Options.
For an example of how to specify the configuration file when setting up a Trading Adapter, see Constructing the Trading Adapter.
Note: Trading Integration API for Java 6.x can only be used with DataSource for Java 6.0.0 and above
The way in which you construct the main Trading Adapter objects has changed in the Trading Integration API for Java 6.0. The following examples illustrate the differences with respect to the equivalent code that uses the Trading DataSource 4.x API.
public class MyTradingApp implements TradingApplicationListener { static void main(String[] args) { new MyTradingApp(); } MyTradingApp() { // Create a factory object for generating the trading state machines. StateMachineFactory myTradingStateMachineFactory = new StateMachineFactory(); // Load the required Trade Models into the factory. myTradingStateMachineFactory.loadModels(new File("conf/MyESPStateModel.xml")); myTradingStateMachineFactory.loadModels(new File("conf/MyRFSStateModel.xml")); // Define the patterns for determining the subjects of Trade objects // that represent messages on Trade Channels, messages on Blotter Channels, // and Blotter Items. Properties subjectProperties = new Properties(); subjectProperties.setProperty("tradechannel.patterns", "/PRIVATE/%U/TRADE/"); subjectProperties.setProperty("blotterchannel.patterns", "/PRIVATE/%U/TRADEBLOTTER/%1"); subjectProperties.setProperty("blotteritem.pattern", "/TRADE/%U/BLOTTER/%1"); // Create a DataSource to manage the communication with // other DataSources, such as Caplin Liberator, // and hence client applications. DataSource dataSource = new DataSource(<dataSourceConfiguration>>, <fieldsConfiguration>); // Create the Trading DataSource. // TradingDataSource implements the standard DataSource callbacks, // which allow you to use the Trading API to communicate with // clients in the form of trade messages. tradingDataSource = new TradingDataSource (this, //Reference to this TradingApplicationListener dataSource, myTradingStateMachineFactory, subjectProperties); // Once the TradingDataSource has been created // it has to be started explicitly. tradingDataSource.start(); } // ... |
The main differences with respect to the construction code for Trading DataSource 4.x are highlighted.
public class MyTradingApp implements TradingApplicationListener { static void main(String[] args) throws Exception { // Create an argument array. In practice, these arguments // would typically be command line arguments. String[] args = new String[3]; args[0] = "--config-file=conf/datasource.conf"; // DataSource configuration args[1] = "--fields-file=conf/fields.conf"; // DataSource message field defs new MyTradingApp(args); } MyTradingApp(String[] arguments) throws Exception { // Create a DataSource to manage the communication with // other DataSources, such as Caplin Liberator, // and hence with client applications. DataSource dataSource = DataSourceFactory.createDataSource(arguments); // Create a TradingProvider // This allows you to use the Trading Integration API to communicate // with clients by means of trade messages. TradingProvider tradingProvider = new TradingProvider (this, // Reference to this TradingApplicationListener dataSource); // The DataSource that this TradingProvider uses // Once the TradingProvider has been created // the DataSource has to be started explicitly. dataSource.start(); } // ... } |
You create an instance of TradingProvider
, which replaces the TradingDataSource
of the
Trading DataSource 4.x API.
You no longer need to create a factory object for generating the trading state machines and then explicitly load the required Trade Models into the factory. The required state machines are now specified in a configuration file. The configuration file also contains patterns for determining the subjects of Trade objects that represent messages (Trade Channels messages, Blotter Channel messages, and Blotter Item messages).
The configuration file is specified as a command option (either --config-file
or
--trading-property-file
) supplied to the created DataSource
object. The internal code of
the Trading Integration library can subsequently access these options as required.
For a detailed description of these options and an example of the typical contents of a configuration file, see Configuration Options.
Trading Integration API 6.0 is not compatible with versions prior to version 6.0.1 of DataSource for Java.
Versions of the Trading Integration API prior to 6.0 required a minimum JVM version of 1.5. Due to Trading Integration API 6.0 now utilizing DataSource 6.0, the minimum JVM version required is 1.6.
The TradingProvider
instance is configured either from a DataSource configuration
file (eg datasource.conf
) or a Java properties file which is specified as an additional command option
(--trading-property-file
) supplied to the created DataSource
object. Values in DataSource
configuration are given precedence over the properties file in case of duplication.
The configuration options specify:
Options can either be defined in DataSource configuration or a properties file using the option names given below
DataSource Configuration Name | Property Name | Default Value | Required? | Description |
blotterchannel-patterns | blotterchannel.patterns | "/TRADEBLOTTER/" | No | Allows the Trading Adapter to determine which Trade objects are requests to open (create) Blotter Channels. For more information on how to specify this property, see "Configuring Trade subjects" in the document Trading 6.0: Integrating The Caplin Platform With A Trading System. |
blotteritem-pattern | blotteritem.pattern | "/BLOTTERITEM" | No | Defines how the Trading Adapter must construct a blotter item subject on the completion of a Trade. For more information on how to specify this property, see "Configuring Trade subjects" in the document Trading 6.0: Integrating The Caplin Platform With A Trading System. |
tradechannel-patterns | tradechannel.patterns | "/TRADE/,/FT/TRADE/" | No | Allows the Trading Adapter to determine which Trade objects belong to which Trade Channels. For example if the pattern is set to "/PRIVATE/%U/TRADE", when a request comes in for the subject "/PRIVATE/john-0/TRADE", this subject will match the pattern. For more information on how to specify this property, see "Configuring Trade subjects" in the document Trading 6.0: Integrating The Caplin Platform With A Trading System. |
trading-audit-logger-pattern | trading.audit.logger.pattern | "logs/audit-%u.log" | No | The pattern that defines the location and name of the audit log.
The pattern can include the %u token. This is a unique number that is automatically generated upon log
file roll over in order to prevent filename conflicts (as defined by the |
trading-models | trading.models | (none) | Yes | Defines the names and locations of the Trade Model configuration XML files. If there is more than one Trade Model, and hence more than one file, separate the file names with commas. For example: trading.models=conf/MyESPStateModel.xml,conf/MyRFSStateModel.xml For more information about Trade Models, see Trade Model Configuration. The format of the Trade Model XML is defined in the document Caplin Trading: Trade Model Configuration XML Reference. |
use-generic-message | use.generic.message | false | No |
Toggles use of the generic message type for trade messages. Generic messages simplify configuration as they
do not require a |
The following options can be specified in datasource.conf
[... General Adapter Configuration ...] # XML configuration files defining trade models used by the Trading Adapter. trading-models conf/MyESPStateModel.xml,conf/MyRFSStateModel.xml # Define subject patterns for TradeChannels, BlotterChannels, and BlotterItems. tradechannel-patterns /PRIVATE/%U/TRADE/ blotterchannel-patterns /PRIVATE/%U/TRADEBLOTTER/%1 blotteritem-pattern /TRADE/%U/BLOTTER/%1 # Define the pattern for the audit log filename and location. trading-audit-logger-pattern myLogsDirectory/audit-%u.log |
Here is an example of a complete properties file:
# Specify the XML configuration files defining # the trade models to be used by the Trading Adapter. trading.models=conf/MyESPStateModel.xml,conf/MyRFSStateModel.xml # Define subject patterns for TradeChannels, # BlotterChannels, and BlotterItems. tradechannel.patterns=/PRIVATE/%U/TRADE/ blotterchannel.patterns=/PRIVATE/%U/TRADEBLOTTER/%1 blotteritem.pattern=/TRADE/%U/BLOTTER/%1 # Define the pattern for the audit log filename and location. trading.audit.logger.pattern=myLogsDirectory/audit-%u.log |
You must create a configuration XML file that represents the Trade Model to be used. If your Trading Adapter uses more than one Trade Model, create a separate XML file for each model.
An example of an ESP trade model is shown below. The conf directory of the kit contains further examples of trade models that are used with Caplin Trader.
<?xml version="1.0" encoding="UTF-8" ?> <tradeModels> <tradeModel name="ESP" initialState="Initial"> <state name="Initial"> <transition target="OpenSent" trigger="Open" source="client"/> </state> <state name="Timeout"/> <state name="OpenSent" timeout="10" timeoutState="Timeout"> <transition target="Opened" trigger="OpenAck" source="server"/> </state> <state name="Opened" timeout="10" timeoutState="Timeout"> <transition target="TradeConfirmed" trigger="TradeConfirmation" source="server"/> <transition target="TradePassed" trigger="Pass" source="server"/> <transition target="TradeExpired" trigger="Expired" source="server"/> </state> <state name="TradeConfirmed"/> <state name="TradePassed"/> <state name="TradeExpired"/> </tradeModel> </tradeModels> |
For more information about Trade Models, see the document Trading 6.0: Integrating The Caplin Platform With A Trading System. The format of the Trade Model XML is defined in Caplin Trading: Trade Model Configuration XML Reference.
First you must specify the names and paths of the files that define the DataSource configuration, and the DataSource
message fields TradingProvider
.
... // Create an argument array. In practice these arguments // would typically be the command line arguments. String[] args = new String[3]; args[0] = "--config-file=conf/datasource.conf"; // DataSource configuration args[1] = "--fields-file=conf/fields.conf"; // DataSource message field defs ... |
Then create a DataSource
object by passing the configuration args to the DataSource
constructor.
... // Create a DataSource. DataSource dataSource = DataSourceFactory.createDataSource(args); ... |
Create the TradingProvider
, passing in a TradingApplicationListener
and DataSource
.
Then start the DataSource
.
The example package contains a working example showing the integration of the Trading Provider with
a simulated Trading System. This example is designed to work out-of-the-box with the Reference
Implementation of Caplin Trader.
Below is an example of only the bare essential code needed to implement a Trading Provider.
|
The objects used to represent Trade and Blotter Channels should be configured in the Liberator with some particular settings to ensure that they behave correctly. These options are used to map objects (so that unique channels are created for every user session), to disable throttling (conflation) and to ensure that the objects are discarded immediately following a user un-subscription or logout.
To ensure that each channel is allocated a uniquely object name for each session, the object-map option with the %U parameter should be used for each Trade or Blotter channel object name. This gives a unique per-session suffix to the requested object.
The following settings are applied within add-object sections of the rttpd.conf configuration file:
For example:
... #trade channel object map object-map /FT/TRADE/FX /FT/TRADE/FX/%U #blotter channel object map object-map /FT/TRADEHISTORY /FT/TRADEHISTORY/%U ... #trade channels add-object name /FT/TRADE type 20 throttle-times 0 discard-timeout 0 end-object #blotter channels add-object name /FT/TRADEHISTORY type 20 throttle-times 0 discard-timeout 0 end-object ... |
For more information on the use of these and other Liberator configuration options, please refer to the Liberator Administration Guide.
In a system where multiple trading systems are integrated using multiple TradingProviders
(typically,
one TradingProvider
per trading system), the client application can request one blotter from the Liberator and see all trades from all
integrated trading systems
in that single blotter. This means that the same client code can handle the blotter regardless of how many TradingProviders
provide
trading services to the client.
The Trading Adapter uses the DataSource
's logger for logging all application messages.
For examples of how to set up a logger, see the package com.caplin.datasource.
All trade events sent and received are logged to an audit log file. The location and name of the log file can be defined as a pattern using the option trading-audit-logger-pattern or trading.audit.logger.pattern. For more details, see Configuration Options.
trading.audit.logger.pattern=myLogsDirectory/audit-%u.log |
If an audit logger pattern has not been set within the configuration file, the default pattern is
set to logs/audit-%u.log
. %u
is a unique number that is automatically generated
upon log file roll over, in order to prevent file name conflicts
(as defined by the java.util.logging.FileHandler
class).
For each event sent and received, two log entries are created: one before
processing the event, and one when the event has been processed.
If the event has been generated by the client, the second log entry is created
after the TradeListener.receiveEvent()
callback has returned. If the event has been generated by the server, the second log entry is
created after the message has been sent.
Note: The audit logging is independent of the standard application logging, which is logged to the named logger as described in Application Log.
All messages received from peers are logged in a packet log file. These messages are stored in a binary format. To render packet logs in a human readable format, the logcat or jlogcat tools should be used. Please refer to the DataSourceJava documentation for more information about packet logging.
As creation and deletion of trade legs can occur on both the client and server, it's important to note the possibility that simultaneous operations may occur on the same leg. For example, both the client and server may attempt to delete the same leg. To overcome this, a simple locking mechanism should be implemented so that only the client or server can perform add/remove operations at one time.
This can easily be achieved by implementing a "Lock" transition in your state model, where a transition back to the current state occurs to signify to the other party that it should prevent any operations until an "Unlock" transition occurs.
Please send bug reports and comments to Caplin support