new module:ct-trading /trademodel /Trade Leg(trade, leg Id)
Constructs an instance of TradeLeg
.
The TradeLeg
class represents the exchange of a financial instrument and the resultant cash flow. One
or more TradeLeg
instances are contained within a single module:ct-trading/trademodel/Trade
instance — this provides the transactional wrapper around a complete trade.
Parameters:
Name | Type | Description |
---|---|---|
trade |
module:ct-trading |
The trade of which this leg is a part. |
legId |
int | The (one based) leg index of this trade leg. |
Throws:
-
if
trade
is not a valid instance ofmodule:ct-trading/trademodel/Trade
. - Type
-
module:ct-core
/Error
Methods
add Data Field Changed Listener(listener, field Name, notify Immediateopt)
Adds a listener that is called when the specified field is updated.
If it's more convenient it's also possible to add leg field listeners directly on the associated
module:ct-trading/trademodel/Trade
instance, where the given field names must have the leg prefix prepended,
e.g. 'L1_Amount' rather than 'Amount'.
N.b. If the notifyImmediate
flag is set to true
and there is a
possibility that the field in question does not have a value at the point the listener is registered, then the first
call to the module:ct-trading/trademodel/DataFieldChangedListener#dataFieldChanged
method may be with an
undefined
value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
listener |
module:ct-trading |
The listener object to add. |
|
fieldName |
String | The field to listen to. |
|
notifyImmediate |
boolean |
<optional> |
if set to |
add Data Fields Changed Listener(listener, field Names)
Adds a listener object that is called when any of the specified fields are updated.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener object to add. |
fieldNames |
Array | The list of fields to send updates for. |
append Trace Data(mTrace Data)
Append trace data into the internal data structure, so it can be sent to the server for analysis. This does not fire any listeners or run any derivations.
Parameters:
Name | Type | Description |
---|---|---|
mTraceData |
Map | Data to be traced. |
data Fields Updated BySubscriber(field Data)
This method is a callback method used by the subscriber to notify the leg when new data is received from the server. The field names arriving from the server are not prefixed with the leg number.
Parameters:
Name | Type | Description |
---|---|---|
fieldData |
module:ct-trading |
The new data from the server. |
get Amount() → {String}
Returns the number of units of the underlying financial instrument to be traded.
Returns:
The number of units
- Type
- String
get Asset Class() → {String}
Returns the type of the financial instrument(s) to be traded — e.g FX, FI, EQUITY or COMMODITIES.
Returns:
The instrument type
- Type
- String
get Field Value(field Name)
Returns the field value with the specified name.
The field name follows the java beans naming convention. For any methods
getXxx()
/setXxx()
there should be a field with the corresponding name, 'xxx'.
Parameters:
Name | Type | Description |
---|---|---|
fieldName |
String | The unique identifier for the field. |
get Instrument() → {String}
Returns the financial instrument that is currently being traded on this leg.
The format of the name is dependent on the asset class. Any processing for specific asset classes should be added
to subclasses of TradeLeg
. The instrument name is generally not understood by Liberator. Liberator
requires a subject name that consists of a concatenation of asset class and instrument name.
Returns:
The instrument
- Type
- String
get Trade() → {module:ct-trading /trademodel /Trade}
Returns the module:ct-trading/trademodel/Trade
object that this leg is a part of.
Returns:
The trade
is Permissioned()
Returns whether the user is permissioned to trade on this leg, based on the results of querying the
module:ct-services/security/PermissionService
singleton.
The permission service is queried based on the instrument that is being traded within the leg
(retrieved via module:ct-trading/trademodel/TradeLeg#getInstrument
) and the the trading protocol being used to perform the trade (retrieved via
module:ct-trading/trademodel/Trade#getTradingProtocol
).
remove Data Field Changed Listener(listener, field Name)
Removes the previously registered DataFieldChangedListener
.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
fieldName |
String | The data field that the listener should be removed from. |
remove Data Fields Changed Listener(listener, field Names)
Removes a listener object from each of the passed fields.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener object to remove. |
fieldNames |
Array | The list of fields to send updates for. |
remove Instrument Data Subscriber()
Removes and unsubscribes the leg from the previously registered
module:ct-trading/trademodel/InstrumentDataSubscriber
.
resume()
Resume a previously suspended indicative data subscription on the trade leg. If there is no indicative data subscription, it does nothing. If this trade leg is not suspended it does nothing.
set Amount(amount)
Sets the number of units of the underlying financial instrument to be traded.
Parameters:
Name | Type | Description |
---|---|---|
amount |
String | The number of units of the underlying financial instrument to be traded. |
set Asset Class(asset Class)
Sets the type of the instrument to be traded — e.g FX, FI, EQUITY or COMMODITIES.
Parameters:
Name | Type | Description |
---|---|---|
assetClass |
String | The asset class that is being traded. |
set Field Value(field Name, sValue)
Sets the value within the trade leg. Initial the trade instance is asked to validate the change. If all is well then the change is made within the leg and the data change listeners are notified (called in response to user input).
Parameters:
Name | Type | Description |
---|---|---|
fieldName |
String | The field name of the field that has changed. |
sValue |
String | The new value of the field |
set Instrument(instrument)
Sets the financial instrument that will be traded on this leg.
Parameters:
Name | Type | Description |
---|---|---|
instrument |
String | The instrument to trade. |
set Instrument Data Subscriber(instrument Data Subscriber)
Sets the InstrumentDataSubscriber
used to be obtain the prices for the instrument.
For certain trade protocols (e.g. ESP) the prices are pre-populated. In this case, when the user initiates the trade the existing price is used.
Parameters:
Name | Type | Description |
---|---|---|
instrumentDataSubscriber |
module:ct-trading |
The subscriber that will retrieve all instrument data for this trade leg. |
stop()
Stops all operations on the trade leg.
This method should be called when the trade leg is no longer needed as it releases any resources held by the
trade leg. This method does not remove listeners that were registered using the module:ct-trading/trademodel/TradeLeg#addDataFieldChangedListener
or module:ct-trading/trademodel/TradeLeg#addDataFieldsChangedListener
methods.
Any data associated with the leg will be cleared when this method is called.
suspend()
Temporarily suspends the indicative data subscription on the trade leg.
If there is no indicative data subscription, or if the trade leg is already suspended, calling this method has no effect.