Class
caplin.trading.trademodel

TradeFactoryRepository

The class is still in Beta and is subject to API changes.
The caplin.trading.trademodel.TradeFactoryRepository class is used to manage the association between data maps and trade factories. A caplin.trading.trademodel.TradeFactory can be retrieved by passing a Map to the caplin.trading.trademodel.TradeFactoryRepository#getTradeFactory method and it can then used to create a caplin.trading.trademodel.Trade object. Alternatively the caplin.trading.trademodel.TradeFactoryRepository#restoreExistingTrade method can be used which will perform the lookup and the trade creation in a single method call.

For example, if a map exists with a TradingProtocol of "ESP" and an AssetClass of "FX":

{ "TradeProtocol": "ESP", "AssetClass": "FX" }

When the caplin.trading.trademodel.TradeFactoryRepository#restoreExistingTrade method is then called with the above map the TradeFactoryRepository searches for a TradeFactory that is capable of creating a Trade for the given map and then creates one using it. For more information on map matching see caplin.trading.trademodel.TradeFactoryRepository#getTradeFactory

A caplin.trading.trademodel.TradeFactory is registered with the TradeFactoryRepository using the caplin.trading.trademodel.TradeFactoryRepository#registerTradeFactory method.

The TradeFactoryRepository implements the caplin.trading.trademodel.TradeFactory interface so it can be used with an instance of caplin.trading.trademodel.TradeMessageService and can encapsulate the logic required to work out which TradeFactory to use to create a new trade following a client or server restore/inflate event.

Constructor Summary

Attributes Name and Description
caplin.trading.trademodel.TradeFactoryRepository( oConfig)

Constructs a new TradeFactoryRepository with the specified arguments.

Method Summary

Attributes Name and Description
void addListener( oTradeFactoryListener)

See the caplin.trading.trademodel.TradeFactory documentation.

caplin.trading.trademodel.TradeFactory getTradeFactory(Map mFieldMap)

Gets a TradeFactory that can create a caplin.trading.trademodel.Trade for the given field map.

void registerTradeFactory(Map mFieldMap, caplin.trading.trademodel.TradeFactory oTradeFactory)

Creates an association between a Map and a TradeFactory.

void restoreExistingTrade( mFieldMap, oTradeMessageService)

See the caplin.trading.trademodel.TradeFactory documentation.

Methods implemented from class caplin.trading.trademodel.TradeFactory:
createNewTrade, restoreNewTrade

Constructor Detail

caplin.trading.trademodel.TradeFactoryRepository( oConfig)

Constructs a new TradeFactoryRepository with the specified arguments.

Parameters
oConfig

Method Detail

void addListener( oTradeFactoryListener)

See the caplin.trading.trademodel.TradeFactory documentation.

Parameters
oTradeFactoryListener
See
caplin.trading.trademodel.TradeFactory#addListener

caplin.trading.trademodel.TradeFactory getTradeFactory(Map mFieldMap)

Gets a TradeFactory that can create a caplin.trading.trademodel.Trade for the given field map.

For a TradeFactory to be returned one must have been registered with a map that has elements that match the parameter mFieldMap.

The ordering of the elements within the map is not important. For example, if a TradeFactory is registered using caplin.trading.trademodel.TradeFactoryRepository#registerTradeFactory with the map:

{ "TradeProtocol": "ESP", "AssetClass": "FX" }

And the #getTradeFactory method is called with a map with the element order reversed the match will succeed and a TradeFactory will be returned.

{ "AssetClass": "FX" "TradeProtocol": "ESP", }

In addition, the requirement is that all map elements from the registered map must be present in the field map. There is no requirement that the map passed to #getTradeFactory cannot contain additional elements. For example, the following would also match because it contains "TradeProtocol" and "AssetClass" with the expected values:

{ "Account": "AccountOne", "AssetClass": "FX" "BaseCurrency": "USD", "TradeProtocol": "ESP", "UserName": "Fred" } It is possible to register multiple trade factory objects with maps that may match. In this scenario the factory that has been registered first will be retrieved by #getTradeFactory.

Parameters
Map mFieldMap The map to be matched against maps registered with a TradeFactory.
Returns
A TradeFactory that can create a caplin.trading.trademodel.Trade for the given field map.

void registerTradeFactory(Map mFieldMap, caplin.trading.trademodel.TradeFactory oTradeFactory)

Creates an association between a Map and a TradeFactory. Trade factories can later be retrieved using #getTradeFactory and are used in calls to {#restoreExistingTrade}. It is possible to register multiple trade factory objects with maps that may match. In this scenario the factory that has been registered first will be retrieved by #getTradeFactory and used by #restoreExistingTrade.

Parameters
Map mFieldMap The field map to be used in matches following calls to #getTradeFactory and #restoreExistingTrade.
caplin.trading.trademodel.TradeFactory oTradeFactory The TradeFactory.

void restoreExistingTrade( mFieldMap, oTradeMessageService)

See the caplin.trading.trademodel.TradeFactory documentation.

Parameters
mFieldMap
oTradeMessageService
See
caplin.trading.trademodel.TradeFactory#restoreExistingTrade