Caplin Trader 5.1.0

Class: module:ct-trading/trademodel/TradeFactoryRepository

module:ct-trading/trademodel/TradeFactoryRepository()

This is in beta and therefore subject to API changes.

The module:ct-trading/trademodel/TradeFactoryRepository class is used to manage the association between data maps and trade factories. A module:ct-trading/trademodel/TradeFactory can be retrieved by passing a Map to the module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory method and it can then used to create a module:ct-trading/trademodel/Trade object. Alternatively the module:ct-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 module:ct-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 module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory

A module:ct-trading/trademodel/TradeFactory is registered with the TradeFactoryRepository using the module:ct-trading/trademodel/TradeFactoryRepository#registerTradeFactory method.

The TradeFactoryRepository implements the module:ct-trading/trademodel/TradeFactory interface so it can be used with an instance of module:ct-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

new module:ct-trading/trademodel/TradeFactoryRepository()

Constructs a new TradeFactoryRepository with the specified arguments.

Implements:

Methods

addListener()

See:
  • module:ct-trading/trademodel/TradeFactory#addListener

getTradeFactory(mFieldMap) → {module:ct-trading/trademodel/TradeFactory}

Gets a TradeFactory that can create a module:ct-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 module:ct-trading/trademodel/TradeFactoryRepository#registerTradeFactory with the map:

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

And the module:ct-trading/trademodel/TradeFactoryRepository#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 module:ct-trading/trademodel/TradeFactoryRepository#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 module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory.

Parameters:
Name Type Description
mFieldMap Map

The map to be matched against maps registered with a TradeFactory.

Returns:

A TradeFactory that can create a module:ct-trading/trademodel/Trade for the given field map.

Type
module:ct-trading/trademodel/TradeFactory

registerTradeFactory(mFieldMap, oTradeFactory)

Creates an association between a Map and a TradeFactory.

Trade factories can later be retrieved using module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory and are used in calls to module:ct-trading/trademodel/TradeFactoryRepository#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 module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory and used by module:ct-trading/trademodel/TradeFactoryRepository#restoreExistingTrade.

Parameters:
Name Type Description
mFieldMap Map

The field map to be used in matches following calls to module:ct-trading/trademodel/TradeFactoryRepository#getTradeFactory and module:ct-trading/trademodel/TradeFactoryRepository#restoreExistingTrade.

oTradeFactory module:ct-trading/trademodel/TradeFactory

The TradeFactory.

restoreExistingTrade()

Implements:
See: