Caplin Trader 5.1.0

Class: module:ct-trading/trademodel/TradeLeg

module:ct-trading/trademodel/TradeLeg(trade, legId)

new module:ct-trading/trademodel/TradeLeg(trade, legId)

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/trademodel/Trade

The trade of which this leg is a part.

legId int

The (one based) leg index of this trade leg.

Implements:
Throws:

if trade is not a valid instance of module:ct-trading/trademodel/Trade.

Type
module:ct-core/Error

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: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/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 to false.

See:

addDataFieldsChangedListener(listener, fieldNames)

Adds a listener object that is called when any of the specified fields are updated.

Parameters:
Name Type Description
listener module:ct-trading/trademodel/DataFieldChangedListener

The listener object to add.

fieldNames Array

The list of fields to send updates for.

See:

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:ct-trading/trademodel/DataHolder

The new data from the server.

getAmount() → {String}

Returns the number of units of the underlying financial instrument to be traded.

See:
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.

See:
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.

See:
Returns:

The instrument

Type
String

getTrade() → {module:ct-trading/trademodel/Trade}

Returns the module:ct-trading/trademodel/Trade object that this leg is a part of.

Returns:

The trade

Type
module:ct-trading/trademodel/Trade

isPermissioned()

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).

removeDataFieldChangedListener(listener, fieldName)

Removes the previously registered DataFieldChangedListener.

Parameters:
Name Type Description
listener module:ct-trading/trademodel/DataFieldChangedListener

The listener to remove.

fieldName String

The data field that the listener should be removed from.

See:

removeDataFieldsChangedListener(listener, fieldNames)

Removes a listener object from each of the passed fields.

Parameters:
Name Type Description
listener module:ct-trading/trademodel/DataFieldChangedListener

The listener object to remove.

fieldNames Array

The list of fields to send updates for.

See:

removeInstrumentDataSubscriber()

Removes and unsubscribes the leg from the previously registered module:ct-trading/trademodel/InstrumentDataSubscriber.

See:

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.

See:

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.

See:

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.

See:

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:ct-trading/trademodel/InstrumentDataSubscriber | InstrumentDataSubscriber

The subscriber that will retrieve all instrument data for this trade leg.

See:

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.