Caplin Trader 5.1.0

Interface: module:ct-trading/service/TradeService

module:ct-trading/service/TradeService

The TradeService behaves as both a factory and repository for trades. It delegates creation of trades to individual factories that are registered with this service.

Methods

addListener(tradeFactoryListener, filteropt)

Register a listener to be informed of trade service events.

Parameters:
Name Type Attributes Description
tradeFactoryListener module:ct-trading/trademodel/TradeFactoryListener

The listener to be informed of the events.

filter function <optional>

allows filtering of returned trades. This function should take a {module:ct-trading/trademodel/Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise.

addTradeRestoredListener(tradeRestoredListener)

Adds a TradeRestoredListener to this service to listen to trade restoration for trades that don't currently exist on the client. If the trade exists on the client, you should add the listener to the Trade object itself.

Parameters:
Name Type Description
tradeRestoredListener module:ct-trading/restoration/TradeRestoredListener

The listener to add.

getTrades(filteropt) → {Array}

Return all trades stored in the trade repository maintained by TradeService.

Parameters:
Name Type Attributes Description
filter function <optional>

Allows filtering of returned trades. This function should take a {module:ct-trading/trademodel/Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise.

Returns:

A list of trades accepted by the filter, or all trades if no filter is provided.

Type
Array

registerTradeFactory(fieldMap, tradeFactory)

Registers a TradeFactory that will be used to create or restore trades when the the trade contains data that matches the criteria in the map provided. 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 used.

Parameters:
Name Type Description
fieldMap Map

The field map to be used to match trade data.

tradeFactory module:ct-trading/trademodel/TradeFactory

The TradeFactory.

removeListener(tradeFactoryListener)

Remove a listener from being informed of trade service events.

Parameters:
Name Type Description
tradeFactoryListener module:ct-trading/trademodel/TradeFactoryListener

The listener to be removed.

removeTrade(cequestID)

Remove completed trade from the service.

Parameters:
Name Type Description
cequestID String

removeTradeRestoredListener(tradeRestoredListener)

Removes a TradeRestoredListener from listening to newly restored trades.

Parameters:
Name Type Description
tradeRestoredListener module:ct-trading/restoration/TradeRestoredListener

The listener to remove.

restoreExistingTrade(trade, fieldMap) → {module:ct-trading/trademodel/Trade}

Invoked from the TradeMessageService.

Parameters:
Name Type Description
trade module:ct-trading/trademodel/Trade
fieldMap Map
Returns:
Type
module:ct-trading/trademodel/Trade

restoreNewTrade(fieldMap) → {module:ct-trading/trademodel/Trade}

Invoked from the TradeMessageService.

Parameters:
Name Type Description
fieldMap Map
Returns:
Type
module:ct-trading/trademodel/Trade