Class TradingProvider

java.lang.Object
com.caplin.trading.TradingProvider
All Implemented Interfaces:
com.caplin.datasource.ConnectionListener

public class TradingProvider extends 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.
  • 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 Details

    • TradingProvider

      public TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource) throws NullPointerException, IllegalArgumentException, 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 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:
      NullPointerException - if no state models have been specified in the trading properties file supplied to the DataSource.
      IOException - if an error occurs while processing the trading properties file.
      IllegalArgumentException
    • TradingProvider

      public TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource, Properties properties) throws NullPointerException, IllegalArgumentException, 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 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:
      NullPointerException - if no state models have been specified in the trading properties file supplied to the DataSource.
      IOException - if an error occurs while processing the trading properties file.
      IllegalArgumentException
    • TradingProvider

      public TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource, TradingProviderConfiguration config) throws NullPointerException, IllegalArgumentException, 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 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.
      config - An object to configure the provider.
      Throws:
      NullPointerException - if no state models have been specified in the trading configuration.
      IOException - if an error occurs while processing the trading configuration.
      IllegalArgumentException
  • Method Details

    • logTradingSystemMessage

      public void logTradingSystemMessage(Level level, 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, 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.
    • onPeerStatus

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