new module:ct-fx /trademodel /FxTrade(leg Factory, state Machine, trade Message Service, trade Protocol, trade Type)
Constructs a FxTrade
.
The FX Trade adds functions specific for FX trades to the generic module:ct-trading/trademodel/Trade
class.
Extends:
Parameters:
Name | Type | Description |
---|---|---|
legFactory |
module:ct-trading |
The Trade leg factory use to create trade legs. Must not be null. |
stateMachine |
module:ct-trading |
A StateMachine suitable for the trading protocol. Must not be null. |
tradeMessageService |
module:ct-trading |
A TradeMessageService responsible for sending trade data to and from the trading system. Must not be null. |
tradeProtocol |
String | The protocol used for trading, for example ESP, RFQ or RFS. |
tradeType |
String | The type of trading this instance will perform, for example SPOT, FORWARD or SWAP. |
Extends
Methods
add Data Field Changed Listener(listener, field Name, notify Immediateopt)
Adds a listener that is called when the specified field is updated.
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 |
- Inherited From:
- See:
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. |
- Inherited From:
- See:
add Derivation(derivation)
Appends a field derivation to the trade model.
Client side field derivations allow new fields to be calculated in response to changes in server-side, or other client-side derived fields.
Parameters:
Name | Type | Description |
---|---|---|
derivation |
module:ct-trading |
The derivation instance to add. |
- Inherited From:
add Invalid Server Event Listener(listener)
Adds a listener that will have its callback method invoked when the server returns data that is somehow invalid. It is expected the client will examine the error and decide on what action to take (e.g. aborting the trade).
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to add. |
- Inherited From:
- See:
add Leg(asset Class) → {module:ct-trading /trademodel /Trade Leg}
Creates a new trade leg with the specified asset class.
Parameters:
Name | Type | Description |
---|---|---|
assetClass |
String | The asset class that leg will be trading. |
- Inherited From:
Throws:
-
if legs cannot be created.
- Type
-
module:ct-core
/Error
Returns:
The newly created leg.
add Legs(asset Class, count) → {Array}
Creates a specified number of new trade legs with of the given asset class.
Parameters:
Name | Type | Description |
---|---|---|
assetClass |
String | The asset class that leg will be trading. |
count |
Integer | The number of legs to be added. |
- Inherited From:
Throws:
-
if legs cannot be created.
- Type
-
module:ct-core
/Error
Returns:
An array of the newly created leg references.
- Type
- Array
add State Changed Listener(listener)
Adds a listener that will have its callback method invoked when the state of the trade is updated.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to add. |
- Inherited From:
- See:
add Structure Changed Listener(listener)
Adds a listener that will have its callback method invoked when legs are added or removed from the trade.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to add. |
- Inherited From:
- See:
add Trade Restored Listener(listener)
Adds a listener to listen to trade restored events.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to add. |
- Inherited From:
add Trading Status Changed Listener(listener)
Adds a specified TradingStatusChangedListener to the trade.
The listener will be notified immediately of current trading state.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to be added. |
add Validator(state, validator)
Adds a validator object that is invoked whenever the trade data is being modified, so it can verify the changes before they are committed.
Parameters:
Name | Type | Description |
---|---|---|
state |
String | The state that will cause the validator to be invoked. |
validator |
module:ct-trading |
The validator to be invoked. |
- Inherited From:
after Leg Added(leg, leg Id)
Checks if this is a second leg being added to the trade, and if so sets the instrument to the same value as the first leg. This assumes that a two legged FX trade represents a swap.
Parameters:
Name | Type | Description |
---|---|---|
leg |
module:ct-trading |
The leg about to be added to the trade. |
legId |
int | The identifier of the leg being added. |
before Leg Added(leg, leg Id)
Invoked before a leg is added to the trade.
This method can be overridden to provide specific functionality for a particular trade type. N.b. At the point at which this call is made, the new leg will not yet be available within the trade object!
Parameters:
Name | Type | Description |
---|---|---|
leg |
module:ct-trading |
The leg about to be added to the trade. |
legId |
int | The identifier of the leg being added. |
- Inherited From:
get Account()
Returns the financial account used for the transfer of funds when the trade is settled.
- Inherited From:
- See:
get Asset Class() → {String}
Returns the type of the financial instrument(s) to be traded — e.g FX, FI, EQUITY or COMMODITIES.
The asset class is only defined at the trade level if all of the trade legs have the same asset class. For exotic trades (cross asset), the asset class is only defined within the leg.
- Inherited From:
Returns:
The instrument's asset class
- Type
- String
get Current State()
Returns the current state of this trade.
- Inherited From:
get Data AsStructured Map(include Legs) → {Object}
Takes data from the trade and trade legs and returns it inside a single DataHolder. This is the inverse operation of decodeData.
Parameters:
Name | Type | Description |
---|---|---|
includeLegs |
Boolean | Determines whether the returned object should include legsFieldData |
- Inherited From:
Returns:
All the trade information as a plain JS object of the form:
{
fieldData: {},
legsFieldData: [
{}, // L1 field data
{}, // L2 field data
...
]
}
- Type
- Object
get Field Value(field Name)
Returns the field value with the specified name.
Field names follow 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. |
- Inherited From:
get Initial Leg Count(trade Type) → {int}
Returns the initial number of legs to be completed in a trade based on the trade type.
Parameters:
Name | Type | Description |
---|---|---|
tradeType |
String | A string representation of the trade type (SPOT, FWD, SWAP or FWDFWDSWAP). |
Returns:
The initial number of legs for this FX trade.
- Type
- int
get Leg(idx) → {module:ct-trading /trademodel /Trade Leg}
Returns the trade leg at the specified index (zero based).
Parameters:
Name | Type | Description |
---|---|---|
idx |
int | The index of the required leg. |
- Inherited From:
Returns:
The located trade leg.
get Leg ById(leg Id) → {module:ct-trading /trademodel /Trade Leg}
Returns the trade leg specified by its ID.
Parameters:
Name | Type | Description |
---|---|---|
legId |
int | The ID of the leg required. |
- Inherited From:
Returns:
The located trade leg.
get Legs() → {Array}
Returns a copy of the list of trade legs.
To prevent corruption, or change of the list by some external party, a copy of the list is returned, rather than the original list itself.
- Inherited From:
Returns:
A list of module:ct-trading/trademodel/TradeLeg
objects.
- Type
- Array
get Max Leg Count(trade Type) → {int}
Returns the maximum number of legs to be completed in a trade based on the trade type.
Parameters:
Name | Type | Description |
---|---|---|
tradeType |
String | A string representation of the trade type (SPOT, FWD, SWAP or FWDFWDSWAP). |
Returns:
The maximum number of legs for this FX trade.
- Type
- int
get Overall Time Out()
Returns the time allowed before the trade will timeout and move to an expired state.
- Inherited From:
get Remaining Time ToTrade()
Returns the time that is left until the trade stops being executable
- Inherited From:
get Request ID()
Returns the unique identifier assigned by the trade subscriber to track this trade instance.
- Inherited From:
- See:
get Restoration ID() → {String}
Returns the ID sent from the server that is used to restore trades.
- Inherited From:
Returns:
The restoration id as sent from the server.
- Type
- String
get Server Failure Message()
Returns an error message containing the reason for a failure if the trade is in an error state — caused by a failure in the server or the network.
- Inherited From:
get State() → {String}
Returns the current state of the trade.
- Inherited From:
Returns:
The trade's current state
- Type
- String
get State Machine()
Returns the state machine associated with this trade.
- Inherited From:
get Trade Channel Status()
Returns only the status of the trade channel and not the pricing channel. Useful for RFQ which are for trades only.
- Inherited From:
get Trade Date() → {String}
The date the trade is/was executed in YYYYMMDD format.
- Inherited From:
- See:
Returns:
The trade date
- Type
- String
get Trade ID()
Returns the unique identifier assigned by the trading system to track this trade instance.
- Inherited From:
- See:
get Trade Meta() → {Object}
- Inherited From:
Returns:
All the trade information as a plain JS object. The legs will be stored in an array un-prefixed.
- Type
- Object
get Trading Protocol() → {String}
Returns the trading protocol that the trade is being executed with.
The trading protocol defines the set of messages that must be passed between the client and server to execute a trade. The actual definitions of the messages, and how the messages are created and consumed is defined within the state machine.
Common examples of trading protocols are ESP (Executable Streaming Price) and RFQ (Request For Quote).
- Inherited From:
Returns:
An identifier representing the trading protocol used by this trade.
- Type
- String
get Trading Status() → {int}
Returns a number indicating whether trading and/or pricing is currently available for this
Trade
or not.
Trading is considered to be unavailable when access to the trading system has been lost. Pricing is
considered to be unavailable if access to the pricing system has been lost - this may be used to
disable trading if the prices are executable.
The possible return values are provided by the module:ct-trading/trademodel/TradingStatus
enumeration.
- Inherited From:
Returns:
TradingStatus.AVAILABLE
if it is possible to trade,
TradingStatus.PRICING_STALE
if pricing is unavailable, otherwise
TradingStatus.UNAVAILABLE
.
- Type
- int
get Trading Type() → {String}
Returns the trading type that this trade is currently executing — e.g. SPOT, FORWARD or SWAP.
- Inherited From:
- See:
Returns:
The trading type
- Type
- String
get User Traded OnBehalf Of() → {String}
Returns the user this trade will be executed on behalf of.
- Inherited From:
- See:
Returns:
The user
- Type
- String
is Event Allowed(event Name) → {boolean}
Returns true
if the specified event name is currently executable, and false
otherwise
(including if the event is unknown).
Parameters:
Name | Type | Description |
---|---|---|
eventName |
String | The name of an executable event. |
- Inherited From:
Throws:
-
if the event name is not a string.
- Type
-
module:ct-core
/Error
Returns:
true
if the event is allowed, otherwise false
.
- Type
- boolean
process Client Event(event Name, trade Fields Mapopt) → {module:ct-trading /validation /Validation Result}
This method is called by the client code to request a state transition. The
module:ct-trading/validation/ValidationResult#getValidationSuccessful
method of the result returned by this
method indicates whether the transition was successful or not. If the transition was successful the appropriate
message will be sent to the trading system. If it failed, the
module:ct-trading/validation/ValidationResult#getErrors
method will return the reason(s) why.
The client code should register itself as a state changed listener to be informed when the state transition occurs
using the module:ct-trading/trademodel/Trade#addStateChangedListener
method.
Please note that if the optional tradeFieldsMap
argument is used, the values will be sent to the
trading system, however they will not be committed to the trade model.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventName |
String | The name of the transition to be executed. |
|
tradeFieldsMap |
Map |
<optional> |
A map of the trade field names/values that will be validated and then sent to
the trading system. If this is omitted or is |
- Inherited From:
Throws:
-
if the state transition fails for any reason.
- Type
-
module:ct-core
/Error
Returns:
A ValidationResult
that indicates whether the state
transition was successful or not.
process Server Event(event Name, server Returned Data)
This method is called by the trade subscriber when messages are received from the server.
The internal state and the data contained by the Trade
are updated to reflect the data sent by the
server. If the sent data is invalid then the trade informs any registered listeners (added via
module:ct-trading/trademodel/Trade#addInvalidServerEventListener
) of any problems.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
String | The name of the transition to be executed — this is the same as the message type sent to the server. |
serverReturnedData |
Map | The message content data sent by the server. |
- Inherited From:
remove All Legs()
Removes all legs from the trade object.
- Inherited From:
Throws:
-
if the leg cannot be found.
- Type
-
module:ct-core
/Error
remove Data Field Changed Listener(listener, field Names)
Removes the previously registered DataFieldChangedListener
.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
fieldNames |
Array | The name of the fields the listener is being deregistered from. |
- Inherited From:
- See:
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. |
- Inherited From:
- See:
remove Invalid Server Event Listener(listener)
Removes the previously registered InvalidServerEventListener
.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
- Inherited From:
- See:
remove Leg(leg)
Removes a leg from the trade object.
Parameters:
Name | Type | Description |
---|---|---|
leg |
module:ct-trading |
The leg to be removed from the trade. |
- Inherited From:
Throws:
-
if the leg cannot be found.
- Type
-
module:ct-core
/Error
remove State Changed Listener(listener)
Removes the previously registered StateChangedListener
.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
- Inherited From:
- See:
remove Structure Changed Listener(listener)
Removes the previously registered StructureChangedListener
.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
- Inherited From:
- See:
remove Trade Restored Listener(listener)
Removes the specified listener from listening to trade restored events.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to remove. |
- Inherited From:
remove Trading Status Changed Listener(listener) → {boolean}
Removes the most recently added TradingStatusChangedListener from the trade.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener to be removed. |
Returns:
true
if the listener has been removed, otherwise
false
.
- Type
- boolean
resume()
Resumes a previously suspended indicative subscription held by the trade.
This method invocation is propagated to the module:ct-trading/trademodel/TradeLeg#resume
method on each of
the trade legs.
- Inherited From:
set Account(account)
Sets the financial account used for the transfer of funds when the trade is settled.
Parameters:
Name | Type | Description |
---|---|---|
account |
String | The account to set. |
- Inherited From:
- See:
set Field Value(field Name, field Value)
Sets the specified field to the specified value. Any associated
module:ct-trading/trademodel/DataFieldChangedListener
s will be notified of the field change.
Parameters:
Name | Type | Description |
---|---|---|
fieldName |
String | The name of the field to set. |
fieldValue |
String | The value to set the field to. |
- Inherited From:
set Trade Date(dt)
Sets the date that the trade was executed.
Parameters:
Name | Type | Description |
---|---|---|
dt |
String | The date in format YYYYMMDD. |
- Inherited From:
- See:
set Trading Type(trading Type)
Sets the trading type that this trade will be executed with.
Parameters:
Name | Type | Description |
---|---|---|
tradingType |
String | The trading type. |
- Inherited From:
- See:
set User Traded OnBehalf Of(user)
Sets user this trade will be executed on behalf of.
Parameters:
Name | Type | Description |
---|---|---|
user |
String | The user to set. |
- Inherited From:
- See:
stop()
Releases any resources held by the trade.
This method must be called when the trade is no longer needed, otherwise resource leaks may occur. This method
invocation is propagated to the module:ct-trading/trademodel/TradeLeg#stop
method on each of the trade legs.
- Inherited From:
suspend()
Temporarily suspends any indicative subscriptions held by the trade.
This method invocation is propagated to the module:ct-trading/trademodel/TradeLeg#suspend
method on each of
the trade legs.
- Inherited From:
update(new Values)
Updates the trade values using the given map. Only new values will be updated.
Parameters:
Name | Type | Description |
---|---|---|
newValues |
Object |
- Inherited From: