How to log in

Brief

The article explains how to log in.

Details

To log in, you should:

  1. Implement the IO2GSessionStatus interface in a status listener class:

    public class MySessionStatusListener implements IO2GSessionStatus { ... }
  2. Create a session:

    O2GSession session = O2GTransport.createSession();
  3. Create an object of a status listener class:

    MySessionStatusListener statusListener = new MySessionStatusListener(...);
  4. Subscribe the status listener object to the session status. It is important to subscribe before the login:

    session.subscribeSessionStatus(statusListener);
  5. Log in using the user ID, password, URL, and connection:

    session.login("userID", "password", "http://www.fxcorporate.com/Hosts.jsp", "Demo");
  6. If you have more than one trading sessions or a pin is required for login, you have to catch the event TRADING_SESSION_REQUESTED in the onSessionStatusChanged function of your status listener.

  7. In this case get O2GSessionDescriptorCollection:

    O2GSessionDescriptorCollection descs = mSession.getTradingSessionDescriptors();
  8. Then process elements of this collection:

    for (O2GSessionDescriptor desc : descs){...}
  9. Finally set a trading session using the session Id and pin:

    mSession.setTradingSession("sessionID", "pin");
  10. Use the status listener onSessionStatusChanged function to capture the CONNECTED event:

  11. Log out when you are done:

    session.logout();
  12. Use the status listener onSessionStatusChanged function to capture the DISCONNECTED event:

  13. Unsubscribe the session from the status listener:

    session.unsubscribeSessionStatus(statusListener);
  14. Dispose the session object:

    session.dispose();

Login and Logout example [show]

See also the simplified login sequence diagram.

See a detailed description of session statuses in the article Session Statuses.

back