The Lab

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

 

Code Block
languagejava
titleListing 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.

 

Info
titleNote

Note that the MFTradingSession object is used for all venues – all but one of the methods on it include

...

a venueID argument.

...



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

...