Caplin Trader 4.7.1

Class: module:caplin/trading/trademodel/TradeFactoryRepository

module:caplin/trading/trademodel/TradeFactoryRepository

This is in beta and therefore subject to API changes.

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

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

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

new module:caplin/trading/trademodel/TradeFactoryRepository()

Constructs a new TradeFactoryRepository with the specified arguments.
Implements:

Methods

addListener()

See:
  • module:caplin/trading/trademodel/TradeFactory#addListener

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

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

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

And the module:caplin/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:caplin/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:caplin/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:caplin/trading/trademodel/Trade for the given field map.
Type
module:caplin/trading/trademodel/TradeFactory

registerTradeFactory(mFieldMap, oTradeFactory)

Creates an association between a Map and a TradeFactory. Trade factories can later be retrieved using module:caplin/trading/trademodel/TradeFactoryRepository#getTradeFactory and are used in calls to module:caplin/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:caplin/trading/trademodel/TradeFactoryRepository#getTradeFactory and used by module:caplin/trading/trademodel/TradeFactoryRepository#restoreExistingTrade.
Parameters:
Name Type Description
mFieldMap Map The field map to be used in matches following calls to module:caplin/trading/trademodel/TradeFactoryRepository#getTradeFactory and module:caplin/trading/trademodel/TradeFactoryRepository#restoreExistingTrade.
oTradeFactory module:caplin/trading/trademodel/TradeFactory The TradeFactory.

restoreExistingTrade()

Implements:
See: