The Lab

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »



First, use the MFFactory class to create an MFClient instance. Second, create an instance of your application's trading handler (which implements the MFTradingHandler interface). Third, use the factory method .newTcpTradingSession() on the MFClient instance to create the trading session object, passing in your application's trading handler. This returns an instance of MFTradingSession, which connects to MarketFactory via TCP. At this point, the dispatch of events to handlers may be started by calling .run() on the client.

Listing 2.1 – creating a trading session
final MFClient client = MFFactory.createMFClient();
final MyTradingHandler handler = new MyTradingHandler(client);
MFTradingSession session = client.newTcpTradingSession(handler, USERNAME, PASSWORD, HOSTNAME, PORT, true);
client.run(); 




Calling newTcpTradingSession() above does not connect and logon the session. Once client.run() is called, and the session starts the first handler function to be called is onStart(). The onStart() handler function is responsible for calling the .logon() method on the session object.
Note that the MFTradingSession object is used for all venues – all but one of the methods on it include a venueID argument.@Override

Listing 2.2 – trading session logon
public void onStart(final MFTradingSession session) {
try {
session.logon();
} catch (MFException e) { System.out.println("Failed to logon."); e.printStackTrace();
System.exit(-1);
}
} 

 

The call to session.logon() will, in the of a successful logon, the on(LogonResponse logonResponse, MFTradingSession session) callback will be called.


  • No labels