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 Detail

      • getState

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

        java.lang.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.
      • createEvent

        TradeEvent createEvent​(java.lang.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

        java.lang.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:
        java.lang.IllegalStateException - Thrown if the RequestId is not set.
      • getField

        java.lang.String getField​(java.lang.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

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

        TradeErrorEvent createErrorEvent​(java.lang.String errorType,
                                         java.lang.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.
      • getLegs

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