Class TradingProvider

  • All Implemented Interfaces:
    com.caplin.datasource.ConnectionListener

    public class TradingProvider
    extends java.lang.Object
    implements com.caplin.datasource.ConnectionListener

    All Trading DataSource applications must create an instance of this class. The class provides the following services.

    • Creates the TradeChannels over which trade messages flow.
    • Creates the BlotterChannels over which blotter messages flow.
    • Validates all trade messages against a trade model that is configured in XML.
    • Communicates with Liberator using the DataSource protocol.

    You must pass in a pre-configured instance of DataSource to the constructor. The DataSource is used for all Liberator communication.

    • Constructor Detail

      • TradingProvider

        public TradingProvider​(TradingApplicationListener listener,
                               com.caplin.datasource.DataSource dataSource)
                        throws java.lang.NullPointerException,
                               java.lang.IllegalArgumentException,
                               java.io.IOException
        Creates a TradingProvider that uses, for Liberator communication, a preconfigured DataSource passed to the constructor.
        Parameters:
        listener - An implementation of TradingApplicationListener. The listener is notified of TradeChannel and BlotterChannel lifecycle events.
        dataSource - A preconfigured DataSource that this TradingProvider uses to communicate with Liberator. For a description of the DataSource class, see the DataSource for Java API Reference.
        Throws:
        java.lang.NullPointerException - if no state models have been specified in the trading properties file supplied to the DataSource.
        java.io.IOException - if an error occurs while processing the trading properties file.
        java.lang.IllegalArgumentException
      • TradingProvider

        public TradingProvider​(TradingApplicationListener listener,
                               com.caplin.datasource.DataSource dataSource,
                               java.util.Properties properties)
                        throws java.lang.NullPointerException,
                               java.lang.IllegalArgumentException,
                               java.io.IOException
        Creates a TradingProvider that uses, for Liberator communication, a preconfigured DataSource passed to the constructor.
        Parameters:
        listener - An implementation of TradingApplicationListener. The listener is notified of TradeChannel and BlotterChannel lifecycle events.
        dataSource - A preconfigured DataSource that this TradingProvider uses to communicate with Liberator. For a description of the DataSource class, see the DataSource for Java API Reference.
        properties - A property object that will be used to configure the provider. If the value is null then the datasource property trading-property-file will be checked for a property file location to be used for the configuration.
        Throws:
        java.lang.NullPointerException - if no state models have been specified in the trading properties file supplied to the DataSource.
        java.io.IOException - if an error occurs while processing the trading properties file.
        java.lang.IllegalArgumentException
    • Method Detail

      • logTradingSystemMessage

        public void logTradingSystemMessage​(java.util.logging.Level level,
                                            java.lang.String message)
        Log a message to the TradingProvider message logger.
        Parameters:
        level - The level to log.
        message - The message to log to the standard log - will be prefixed in the log file with "Trading System Message:"
      • terminate

        public void terminate()
        Closes all channels and cleans up all trades.
      • createTrade

        public Trade createTrade​(TradeChannel tradeChannel,
                                 java.lang.String tradingProtocol)
                          throws TradeException
        Creates a new Trade and restores it to the specified channel, setting the requestId to a generated value.

        This is used for restoring trades from a trading system through this API, rather than the normal process of creating a trade which is done as a result of a client message.

        Parameters:
        tradeChannel - the TradeChannel to create the new trade on
        tradingProtocol - the protocol for this trade
        Returns:
        the Trade instance that has been restored onto the provided TradeChannel
        Throws:
        TradeException - if there was a problem creating the Trade or restoring it to the provided TradeChannel
      • getDataSource

        public com.caplin.datasource.DataSource getDataSource()
        The underlying DataSource object that is used for communication with the Liberator.
        Returns:
        the DataSource object that is in use - normally you won't need to access this.
      • addBlotterTradeListener

        @Deprecated
        public void addBlotterTradeListener​(BlotterChannel blotterChannel,
                                            BlotterTradeListener listener)
        Deprecated.
        Registers the provided listener to receive auto-generated trade lifecycle blotter events for matching trades.

        Any trades that occur on any TradeChannel that open to a user that matches the BlotterChannel.getUserName() will have blotter events automatically sent to the provided listener as they occur.

        Currently only a single listener can be registered per-channel.

        This method is usually called as a result of a TradingApplicationListener.blotterChannelCreated(BlotterChannel) callback.

        Parameters:
        blotterChannel - The blotter channel that should be used to match trades that should have blotter events sent to the listener.
        listener - the BlotterTradeListener that should receive auto-generated blotter events.

        Deprecated: Use the new Blotter API (com.caplin.datasource.blotter).

      • removeBlotterTradeListener

        @Deprecated
        public void removeBlotterTradeListener​(BlotterChannel blotterChannel,
                                               BlotterTradeListener listener)
        Deprecated.
        De-registers the provided listener from receiving auto-generated trade lifecycle blotter events.

        This method is usually called as a result of a TradingApplicationListener.blotterChannelClosed(BlotterChannel) callback.

        Parameters:
        blotterChannel - the blotter channel that was used to register the listener
        listener - the listener that should no longer receive auto-generated blotter events.

        Deprecated: Use the new Blotter API (com.caplin.datasource.blotter).

      • onPeerStatus

        public void onPeerStatus​(com.caplin.datasource.PeerStatusEvent peerStatusEvent)
        Specified by:
        onPeerStatus in interface com.caplin.datasource.ConnectionListener