Constructor
new module:caplin/trading/trademodel/TradeLeg(trade, legId)
caplin.trading.trademodel.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:caplin/trading/trademodel/Trade
instance — this provides the transactional wrapper around a complete trade.
Parameters:
Name | Type | Description |
---|---|---|
trade |
module:caplin/trading/trademodel/Trade | 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:caplin/trading/trademodel/Trade
.
Methods
-
addDataFieldChangedListener(listener, fieldName, notifyImmediateopt)
-
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:caplin/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 totrue
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 themodule:caplin/trading/trademodel/DataFieldChangedListener#dataFieldChanged
method may be with anundefined
value.Parameters:
Name Type Attributes Description listener
module:caplin/trading/trademodel/DataFieldChangedListener The listener object to add. fieldName
String The field to listen to. notifyImmediate
boolean <optional>
if set to true
then the listener will be immediately notified of the fields current value, otherwise the listener will first be notified immediately the field changes value. If omitted it defaults tofalse
. -
addDataFieldsChangedListener(listener, fieldNames)
-
Adds a listener object that is called when any of the specified fields are updated.
Parameters:
Name Type Description listener
module:caplin/trading/trademodel/DataFieldChangedListener The listener object to add. fieldNames
Array The list of fields to send updates for. -
appendTraceData(mTraceData)
-
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. -
dataFieldsUpdatedBySubscriber(fieldData)
-
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:caplin/trading/trademodel/DataHolder The new data from the server. -
getAmount() → {String}
-
Returns the number of units of the underlying financial instrument to be traded.
Returns:
The number of units- Type
- String
-
getAssetClass() → {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
-
getFieldValue(fieldName)
-
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. -
getInstrument() → {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
-
getTrade() → {module:caplin/trading/trademodel/Trade}
-
Returns the
module:caplin/trading/trademodel/Trade
object that this leg is a part of.Returns:
The trade -
isPermissioned()
-
Returns whether the user is permissioned to trade on this leg, based on the results of querying the
module:caplin/services/security/PermissionService
singleton.The permission service is queried based on the instrument that is being traded within the leg (retrieved via
module:caplin/trading/trademodel/TradeLeg#getInstrument
) and the the trading protocol being used to perform the trade (retrieved viamodule:caplin/trading/trademodel/Trade#getTradingProtocol
). -
removeDataFieldChangedListener(listener, fieldName)
-
Removes the previously registered
DataFieldChangedListener
.Parameters:
Name Type Description listener
module:caplin/trading/trademodel/DataFieldChangedListener The listener to remove. fieldName
String The data field that the listener should be removed from. -
removeDataFieldsChangedListener(listener, fieldNames)
-
Removes a listener object from each of the passed fields.
Parameters:
Name Type Description listener
module:caplin/trading/trademodel/DataFieldChangedListener The listener object to remove. fieldNames
Array The list of fields to send updates for. -
removeInstrumentDataSubscriber()
-
Removes and unsubscribes the leg from the previously registered
module:caplin/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.
-
setAmount(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. -
setAssetClass(assetClass)
-
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. -
setFieldValue(fieldName, 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 -
setInstrument(instrument)
-
Sets the financial instrument that will be traded on this leg.
Parameters:
Name Type Description instrument
String The instrument to trade. -
setInstrumentDataSubscriber(instrumentDataSubscriber)
-
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:caplin/trading/trademodel/InstrumentDataSubscriber | InstrumentDataSubscriber 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:caplin/trading/trademodel/TradeLeg#addDataFieldChangedListener
ormodule:caplin/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.