Interface Trade


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.

  • Method Details

    • getState

      String getState()
      Gets the current state of this Trade.
      Returns:
      The name of the current state.
    • getType

      String getType()
      Gets the type of this Trade. The Type of a Trade represents the Trade Protocol/Model for this Trade.
      Returns:
      The type of this Trade.
    • getChannel

      TradeChannel getChannel()
      Gets the Trade Channel for this Trade.
      Returns:
      The TradeChannel.
    • createEvent

      TradeEvent createEvent(String type) throws TradeException
      Creates an event for this Trade. The created TradeEvent is tied to this Trade and is set up with the correct RequestId and TradeId.
      Parameters:
      type - The type of the event.
      Returns:
      The new event.
      Throws:
      TradeException - Thrown if the type is invalid or the event cannot be created.
    • sendEvent

      void sendEvent(TradeEvent event) throws TradeException
      Sends an TradeEvent created by this Trade. The TradeEvent is processed by the Trade Model for this Trade and if appropriate is sent to the client.
      Parameters:
      event - The event to send.
      Throws:
      TradeException - Thrown if the event cannot be sent.
    • getRequestId

      String getRequestId()
      Gets the unique RequestId for this Trade. The RequestId represents a unique identifier set by the client for this Trade, or set by the TradingDataSource if the trade is a restored trade.
      Returns:
      The RequestId.
      Throws:
      IllegalStateException - Thrown if the RequestId is not set.
    • setTradeListener

      void setTradeListener(TradeListener listener)
      Sets the TradeListener for this trade. The TradeListener will be notified when TradeEvents are received for this Trade.
      Parameters:
      listener - The TradeListener.
    • getTradeListener

      TradeListener getTradeListener()
      Gets the TradeListener that is set on this Trade.
      Returns:
      The TradeListener, or null if no TradeListener is set.
    • getField

      String getField(String fieldName)
      Gets a stored field value from this Trade. This will typically be the context fields that have been stored as a result of the aggregated affect of all the processed TradeEvents.
      Parameters:
      fieldName - the String field name identifier to retrieve
      Returns:
      The field value for the provided field name, or null if there is no value stored.
    • getFields

      Map<String,String> getFields()
      Gets the fields of this Trade as a Map.
      Returns:
      A map of the fields.
    • createErrorEvent

      TradeErrorEvent createErrorEvent(String errorType, String errorDescription) throws TradeException
      Creates an error event for this Trade. The created TradeErrorEvent is tied to this Trade and is set up with the correct RequestId and TradeId.
      Parameters:
      errorType - they type of Error, which correlates to an error transition in the underlying state-model.
      errorDescription - an informative message that summarises the error.
      Returns:
      The new event.
      Throws:
      TradeException - Thrown if the type is invalid or the event cannot be created.
    • sendErrorEvent

      void sendErrorEvent(TradeErrorEvent errorEvent) throws TradeException
      Sends a TradeErrorEvent created by this Trade. The TradeErrorEvent is processed by the Trade Model for this Trade and is always sent to the client.
      Parameters:
      errorEvent - The error event to send.
      Throws:
      TradeException - Thrown if the event cannot be sent.
    • createRestoreEvent

      TradeEvent createRestoreEvent(String restoreToState) throws TradeException
      Creates an event that will restore a trade into the specified state. The trade must be created with TradeChannel.restoreTrade(String, String, String).
      Parameters:
      restoreToState - The name of the state to restore into. This must correspond to a state within the state model.
      Returns:
      The trade event to restore a trade into the specified state.
      Throws:
      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.
    • createLeg

      Leg createLeg()
      Creates a new trade leg on this trade. Note that in order to notify trading clients that the leg has been added it is necessary to follow these steps:
      Returns:
      The new trade leg.
    • getLegs

      List<Leg> getLegs()
      Gets a copy of the list of legs that comprise this trade, in the correct order.
      Returns:
      The list of legs.