Interface
caplin.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.

Constructor Summary

Attributes Name and Description
caplin.trading.service.TradeService()

Method Summary

Attributes Name and Description
void addListener(caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener, Function (optional))

Register a listener to be informed of trade service events.

void addTradeRestoredListener(caplin.trading.restoration.TradeRestoredListener tradeRestoredListener)

Adds a TradeRestoredListener to this service to listen to trade restoration for trades that don't currently exist on the client.

Array getTrades(Function filter)

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

void registerTradeFactory(Map fieldMap, caplin.trading.trademodel.TradeFactory 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.

void removeListener(caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener)

Remove a listener from being informed of trade service events.

void removeTrade(String cequestID)

Remove completed trade from the service.

void removeTradeRestoredListener(caplin.trading.restoration.TradeRestoredListener tradeRestoredListener)

Removes a TradeRestoredListener from listening to newly restored trades.

caplin.trading.trademodel.Trade restoreExistingTrade(caplin.trading.trademodel.Trade trade, Map fieldMap)

Invoked from the TradeMessageService.

caplin.trading.trademodel.Trade restoreNewTrade(Map fieldMap)

Invoked from the TradeMessageService.

Constructor Detail

caplin.trading.service.TradeService()

Method Detail

void addListener(caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener, Function (optional))

Register a listener to be informed of trade service events.

Parameters
caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener The listener to be informed of the events.
Function (optional) filter allows filtering of returned trades. This function should take a {caplin.trading.trademodel.Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise.

void addTradeRestoredListener(caplin.trading.restoration.TradeRestoredListener 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
caplin.trading.restoration.TradeRestoredListener tradeRestoredListener The listener to add.

Array getTrades(Function filter)

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

Parameters
Function filter (Optional) Allows filtering of returned trades. This function should take a {caplin.trading.trademodel.Trade} as its only argument, and should return true if the given Trade is accepted by the filter, and false otherwise.
Returns
{Array} A list of trades accepted by the filter, or all trades if no filter is provided.

void registerTradeFactory(Map fieldMap, caplin.trading.trademodel.TradeFactory 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
Map fieldMap The field map to be used to match trade data.
caplin.trading.trademodel.TradeFactory tradeFactory The TradeFactory.

void removeListener(caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener)

Remove a listener from being informed of trade service events.

Parameters
caplin.trading.trademodel.TradeFactoryListener tradeFactoryListener The listener to be removed.

void removeTrade(String cequestID)

Remove completed trade from the service.

Parameters
String cequestID

void removeTradeRestoredListener(caplin.trading.restoration.TradeRestoredListener tradeRestoredListener)

Removes a TradeRestoredListener from listening to newly restored trades.

Parameters
caplin.trading.restoration.TradeRestoredListener tradeRestoredListener The listener to remove.

caplin.trading.trademodel.Trade restoreExistingTrade(caplin.trading.trademodel.Trade trade, Map fieldMap)

Invoked from the TradeMessageService.

Parameters
caplin.trading.trademodel.Trade trade
Map fieldMap
Returns
{caplin.trading.trademodel.Trade}

caplin.trading.trademodel.Trade restoreNewTrade(Map fieldMap)

Invoked from the TradeMessageService.

Parameters
Map fieldMap
Returns
{caplin.trading.trademodel.Trade}