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
add Listener(trade Factory Listener, filteropt)
Register a listener to be informed of trade service events.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tradeFactoryListener |
module:ct-trading |
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. |
add Trade Restored Listener(trade Restored Listener)
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 |
The listener to add. |
get Trades(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
register Trade Factory(field Map, trade Factory)
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 |
The TradeFactory. |
remove Listener(trade Factory Listener)
Remove a listener from being informed of trade service events.
Parameters:
Name | Type | Description |
---|---|---|
tradeFactoryListener |
module:ct-trading |
The listener to be removed. |
remove Trade(cequest ID)
Remove completed trade from the service.
Parameters:
Name | Type | Description |
---|---|---|
cequestID |
String |
remove Trade Restored Listener(trade Restored Listener)
Removes a TradeRestoredListener from listening to newly restored trades.
Parameters:
Name | Type | Description |
---|---|---|
tradeRestoredListener |
module:ct-trading |
The listener to remove. |
restore Existing Trade(trade, field Map) → {module:ct-trading /trademodel /Trade}
Invoked from the TradeMessageService.
Parameters:
Name | Type | Description |
---|---|---|
trade |
module:ct-trading |
|
fieldMap |
Map |
Returns:
restore New Trade(field Map) → {module:ct-trading /trademodel /Trade}
Invoked from the TradeMessageService.
Parameters:
Name | Type | Description |
---|---|---|
fieldMap |
Map |