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.- Implementations:
Methods
-
addListener(tradeFactoryListener, filteropt)
-
Register a listener to be informed of trade service events.
Parameters:
Name Type Attributes Description tradeFactoryListener
module:caplin/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:caplin/trading/trademodel/Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise. - Implementations:
-
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:caplin/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:caplin/trading/trademodel/Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise. - Implementations:
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:caplin/trading/trademodel/TradeFactory The TradeFactory. -
removeListener(tradeFactoryListener)
-
Remove a listener from being informed of trade service events.
Parameters:
Name Type Description tradeFactoryListener
module:caplin/trading/trademodel/TradeFactoryListener The listener to be removed. - Implementations:
-
removeTrade(cequestID)
-
Remove completed trade from the service.
Parameters:
Name Type Description cequestID
String - Implementations:
-
removeTradeRestoredListener(tradeRestoredListener)
-
Removes a TradeRestoredListener from listening to newly restored trades.
Parameters:
Name Type Description tradeRestoredListener
module:caplin/trading/restoration/TradeRestoredListener The listener to remove. -
restoreExistingTrade(trade, fieldMap) → {module:caplin/trading/trademodel/Trade}
-
Invoked from the TradeMessageService.
Parameters:
Name Type Description trade
module:caplin/trading/trademodel/Trade fieldMap
Map Returns:
-
restoreNewTrade(fieldMap) → {module:caplin/trading/trademodel/Trade}
-
Invoked from the TradeMessageService.
Parameters:
Name Type Description fieldMap
Map - Implementations:
Returns: