Interface TradingApplicationListener


  • public interface TradingApplicationListener
    Use the TradingApplicationListener interface to be notified of TradeChannel and BlotterChannel lifecycle events.

    Users' trading channels are represented by TradeChannels. Typically a user has a single TradeChannel to perform multiple Trades (though it is possible to configure different trade channels to be used by the same user, for example to split asset classes or trade categories, if desired). The TradingApplicationListener is notified when a new TradeChannel is created and when a TradeChannel is closed.

    Users' blotter messaging channels are represented by BlotterChannels. A blotter channel is created when a user opens a blotter on the client. The channelCreated(TradeChannel) method will be called, and this call should be used to communicate with an external system to retrieve / register for trade history information. If you wish to receive auto-generated BlotterEvents containing notifications of trade lifecycle events, this is also the point at which you should register a BlotterTradeListener with the TradingProvider.addBlotterTradeListener(BlotterChannel, BlotterTradeListener) method.

    • Method Detail

      • channelCreated

        void channelCreated​(TradeChannel channel)
                     throws TradeException
        Called when a client wants to open a trading channel that will subsequently be used to perform trades. This allows any channel/user specific initialization to be performed.
        Parameters:
        channel - A trade channel that represents a particular user's session with the TradingDataSource.
        Throws:
        TradeException - Thrown if it is not possible to accept this trade channel, or the associated user.
      • channelClosed

        void channelClosed​(TradeChannel channel)
        Called when a channel is closed as a result of the user finishing its trading session or the connection being lost to the Liberator. This enables any clean up associated with a channel/user to be performed.
        Parameters:
        channel - The TradeChannel.
      • blotterChannelCreated

        @Deprecated
        void blotterChannelCreated​(BlotterChannel blotterChannel)
        Deprecated.
        Called when a BlotterChannel is created as a result of a user requesting a blotter subject. Currently requests for subjects of the form /FT/TRADEHISTORY/... or /BLOTTER/... will be routed to this callback.

        The example singleton can be used to generate automatic blotter messages from Trade events, by registering an instance of it with the TradingDataSource using TradingProvider.addBlotterTradeListener(BlotterChannel, BlotterTradeListener) within this callback.

        Example implementation:

        ...
        public void blotterChannelCreated( BlotterChannel blotterChannel )
        {
            // request from backend system some historic trade information (using an example 
            // class "HistoricalTrade" that comes from the Trading System
            HistoricTrade[] historicTrades = tradingSystem.getHistoricTrades(blotterChannel.getUserName());
            sendHistoricTrades(blotterChannel, historicTrades);
            
            // also register for automatic blotter events for TradingDataSource managed trades
            tradingDataSource.addBlotterTradeListener(blotterChannel, AutoBlotterTradeListener.getInstance());        
        }
        
        private void sendHistoricTrades(BlotterChannel blotterChannel, HistoricTrades[] historicTrades)
        {
            for (trade : historicTrades)
            {
                BlotterMessage blotterMessage = blotterChannel.createBlotterMessage();
            
                // for each field in the blotter (these are just examples of the fields that may be present on
                // the class "HistoricTrade"
                blotterMessage.addField("TradeID", trade.getId());
                blotterMessage.addField("L1_Price", trade.getExecutedPrice());
                blotterMessage.addField("Status", trade.getStatus());
                // etc.
                
                // send the blotter message
                blotterChannel.sendBlotterMessage(blotterMessage);
            }
        }
        ... 
        
        Parameters:
        blotterChannel - The BlotterChannel.
        See Also:
        TradingProvider.addBlotterTradeListener(BlotterChannel, BlotterTradeListener), Deprecated: Use the new Blotter API (com.caplin.datasource.blotter).
      • blotterChannelClosed

        @Deprecated
        void blotterChannelClosed​(BlotterChannel blotterChannel)
        Deprecated.
        Called when a BlotterChannel is closed as a result of a user no longer being interested in this particular blotter configuration or the connection being lost to the Liberator. This enables cleanup or removing of listeners.
        Parameters:
        blotterChannel - The BlotterChannel. Deprecated: Use the new Blotter API (com.caplin.datasource.blotter).
      • peerUp

        void peerUp​(int peerIndex)
        Called when a peer connection is established.

        This can be either the an initial peer connection after startup or a re-established connection following a peerDown(int) call.

        Parameters:
        peerIndex - the index of the peer that has just connected. This is a 0 indexed id based on the peer configuration order.
      • peerDown

        void peerDown​(int peerIndex)
        Called when a peer connection is lost.

        This indicates that the connection to the remote peer (usually a Liberator) has been lost.

        Currently this should be treated as a catastrophic event for all open TradeChannels and Trades, and as such the upstream system should be notified of errors. Future version of the TradingDataSource will provide the ability to re-establish in-progress Trades (and associated channels). The behaviour after a connection lost is that this call will be followed by calls to channelClosed(TradeChannel) for any active TradeChannels for the peer.

        Parameters:
        peerIndex - the index of the peer that has just disconnected. This is a 0 indexed id based on the peer configuration order.