After instantiating an MFClient object, call newTcpTradingSession(), passing it your trading handler, which implements the MFTradingHandler interface. The handler interface is described in the next chapter.
This method takes MarketFactory login credentials (username and password), and a MarketFactory server address (hostname and port). The boolean option autoRelogon is used to indicate if the MFSession instance should automatically re-logon when a disconnection of the MFClient from the MarketFactory server occurs.
Once the session is created, call run() to start the event loop, which dispatches incoming events from MarketFactory to the functions defined in the user-provided trading and market data handlers. The thread that calls this run() will be used to drive the callbacks and will only be returned when the client is terminated. Subsequent calls to run() will fail.
Calling run() triggers the onStart method on any registered handlers.
The preferred method of disconnection is sending logoutRequest() for each session and then calling stop.
To stop dispatching events abruptly, call stop This stops the event loop, closes open sockets and returns the originally trapped thread. Calling stop triggers the onStop method on all registered handlers. This may be called from an external thread or internally from a handler.
/** * Creates a session for connecting to a particular * venue gateway over TCP. * * @param port specify 0 to have it automatically choose port. * @param autoRelogon automatically relogons when a disconnection occurs. */ MFMarketDataSession newTcpMarketDataSession(MFMarketDataHandler handler, String venueName, long venueID, String username, String password, String hostname, int port, boolean autoRelogon) throws MFException; |
/** * Creates a session for connecting to a particular * venue gateway over TCP. * * @param port specify 0 to have it automatically choose port. * @param reconnectOnDisconnect automatically reconnects when a disconnection occurs. **/ MFMarketDataSession newTcpMarketDataPriceDepthBookSession(MFPriceDepthBookHandler handler, String venueName, long venueID, String username, String password, String hostname, int port, boolean reconnectOnDisconnect) throws MFException; |
Notice that a newTcpMarketDataSession expects a MFMarketDataHandler while newTcpMarketDataPriceDepthBookSession expects a MFPriceDepthBookHandler
As for the newTcpTradingSession() method, both of these market data-related methods take MarketFactory login credentials (username and password), and MarketFactory server address details (hostname and port). The boolean option autoReconnect is used to indicate if the MFClient instance should automatically re-logon when a disconnection of the MFClient from the MarketFactory server occurs.
TradingSessionMFTradingHandler
onStart()
logon()
onConnect()
onLogonResponse()
callbacks
logout()
logoutResponse()
onDisconnect()
Figure 1.1. – Showing the flow to demonstrate the session lifecycle of a session. Trading is shown, but
MarketData is similar.The MFClient layer lives in the directory $MFAPI/MFClient/.
MFClient is the central class for managing sessions with MarketFactory. Session objects are generated by the factory methods of MFClient, and are automatically registered with this instance of MFClient.
com.marketfactory.api contains interfaces, while the packages under com.marketfactory.internal
contains the implementations.