public interface Trade
A single Trade active in the system.
A Trade is initiated by a client and is tied to a TradeChannel
. The lifecycle of a Trade consists
of a number of messages, represented by TradeEvents, being sent between the client and the
Trading System in both directions. These messages cause the Trade to transition between a number
of predefined states.
Trades are comprised of one or more trade legs, which each leg representing the exchange of a financial instrument and the resultant cashflow. It is possible to add, remove and update trades from the client or from the TradingDataSource.
A Trade is uniquely identified in two ways: by RequestId set by the client and a TradeId set by the Trading System.
Modifier and Type | Method and Description |
---|---|
TradeErrorEvent |
createErrorEvent(java.lang.String errorType,
java.lang.String errorDescription)
Creates an error event for this Trade.
|
TradeEvent |
createEvent(java.lang.String type)
Creates an event for this Trade.
|
Leg |
createLeg()
Creates a new trade leg on this trade.
|
TradeEvent |
createRestoreEvent(java.lang.String restoreToState)
Creates an event that will restore a trade into the specified state.
|
TradeChannel |
getChannel()
Gets the Trade Channel for this Trade.
|
java.lang.String |
getField(java.lang.String fieldName)
Gets a stored field value from this Trade.
|
java.util.Map<java.lang.String,java.lang.String> |
getFields()
Gets the fields of this Trade as a Map.
|
java.util.List<Leg> |
getLegs()
Gets a copy of the list of legs that comprise this trade, in the correct order.
|
java.lang.String |
getRequestId()
Gets the unique RequestId for this Trade.
|
java.lang.String |
getState()
Gets the current state of this Trade.
|
TradeListener |
getTradeListener()
Gets the
TradeListener that is set on this Trade. |
java.lang.String |
getType()
Gets the type of this Trade.
|
void |
sendErrorEvent(TradeErrorEvent errorEvent)
Sends a TradeErrorEvent created by this Trade.
|
void |
sendEvent(TradeEvent event)
Sends an
TradeEvent created by this Trade. |
void |
setTradeListener(TradeListener listener)
Sets the
TradeListener for this trade. |
java.lang.String getState()
java.lang.String getType()
TradeChannel getChannel()
TradeChannel
.TradeEvent createEvent(java.lang.String type) throws TradeException
TradeEvent
is tied to this Trade and is set up
with the correct RequestId and TradeId.type
- The type of the event.TradeException
- Thrown if the type is invalid or the event cannot be created.void sendEvent(TradeEvent event) throws TradeException
TradeEvent
created by this Trade. The TradeEvent
is processed by the Trade Model for
this Trade and if appropriate is sent to the client.event
- The event to send.TradeException
- Thrown if the event cannot be sent.java.lang.String getRequestId()
java.lang.IllegalStateException
- Thrown if the RequestId is not set.void setTradeListener(TradeListener listener)
TradeListener
for this trade. The TradeListener
will be notified when TradeEvents are
received for this Trade.listener
- The TradeListener
.TradeListener getTradeListener()
TradeListener
that is set on this Trade.TradeListener
, or null if no TradeListener
is set.java.lang.String getField(java.lang.String fieldName)
fieldName
- the String field name identifier to retrievejava.util.Map<java.lang.String,java.lang.String> getFields()
TradeErrorEvent createErrorEvent(java.lang.String errorType, java.lang.String errorDescription) throws TradeException
TradeErrorEvent
is tied to this Trade and is set up
with the correct RequestId and TradeId.errorType
- they type of Error, which correlates to an error transition in the underlying state-model.errorDescription
- an informative message that summarises the error.TradeException
- Thrown if the type is invalid or the event cannot be created.void sendErrorEvent(TradeErrorEvent errorEvent) throws TradeException
TradeErrorEvent
is processed by the Trade Model for
this Trade and is always sent to the client.errorEvent
- The error event to send.TradeException
- Thrown if the event cannot be sent.TradeEvent createRestoreEvent(java.lang.String restoreToState) throws TradeException
TradeChannel.restoreTrade(String, String, String)
.restoreToState
- The name of the state to restore into. This must correspond
to a state within the state model.TradeException
- Thrown if this trade was not constructed with TradeChannel.restoreTrade(String, String, String)
or if an attempt to restore a trade that is not currenly in the initial state.Leg createLeg()
Leg
by calling createLeg()
.LegAction
representing the addition by calling Leg.createAddLegAction()
.LegAction.addField(String, int)
or LegAction.addField(String, String)
methods.TradeEvent
by calling createEvent(String)
.TradeEvent.addLegAction(LegAction)
.sendEvent(TradeEvent)
method.java.util.List<Leg> getLegs()
Please send bug reports and comments to Caplin support