Package com.caplin.trading
Class TradingProvider
java.lang.Object
com.caplin.trading.TradingProvider
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionTradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource) Creates aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor.TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource, TradingProviderConfiguration config) Creates aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor.TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource, Properties properties) Creates aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor. -
Method Summary
Modifier and TypeMethodDescriptioncreateTrade(TradeChannel tradeChannel, String tradingProtocol) Creates a new Trade and restores it to the specified channel, setting the requestId to a generated value.com.caplin.datasource.DataSourceThe underlying DataSource object that is used for communication with the Liberator.voidlogTradingSystemMessage(Level level, String message) Log a message to the TradingProvider message logger.voidonPeerStatus(com.caplin.datasource.PeerStatusEvent peerStatusEvent) voidCloses all channels and cleans up all trades.
-
Constructor Details
-
TradingProvider
public TradingProvider(TradingApplicationListener listener, com.caplin.datasource.DataSource dataSource) throws NullPointerException, IllegalArgumentException, IOException Creates aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor.- Parameters:
listener- An implementation ofTradingApplicationListener. The listener is notified ofTradeChannellifecycle events.dataSource- A preconfiguredDataSourcethat thisTradingProvideruses to communicate with Liberator. For a description of theDataSourceclass, see the DataSource for Java API Reference.- Throws:
NullPointerException- if no state models have been specified in the trading properties file supplied to theDataSource.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 aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor.- Parameters:
listener- An implementation ofTradingApplicationListener. The listener is notified ofTradeChannellifecycle events.dataSource- A preconfiguredDataSourcethat thisTradingProvideruses to communicate with Liberator. For a description of theDataSourceclass, 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 theDataSource.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 aTradingProviderthat uses, for Liberator communication, a preconfiguredDataSourcepassed to the constructor.- Parameters:
listener- An implementation ofTradingApplicationListener. The listener is notified ofTradeChannellifecycle events.dataSource- A preconfiguredDataSourcethat thisTradingProvideruses to communicate with Liberator. For a description of theDataSourceclass, 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
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
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 ontradingProtocol- 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:
onPeerStatusin interfacecom.caplin.datasource.ConnectionListener
-