How to log in

Brief

The article explains how to log in step by step.

Details

To log in, you should:

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

    class CSessionStatusListener : public IO2GSessionStatus {...}
  2. Create a session:

    IO2GSession *pSession = CO2GTransport::createSession();
  3. Create an instance of the session status listener:

    CSessionStatusListener *sessionStatusListener = new CSessionStatusListener(&log, pSession, &oLoginData);
  4. Subscribe the status listener object to the session status.
    It is important to subscribe before the login:

    pSession->subscribeSessionStatus(sessionStatusListener);
  5. The events are coming asynchronously. They should come in another thread. When an event comes, a signal will be sent to the main thread.

  6. If you have more than one trading sessions or pin is required for login, you have to catch the event TradingSessionRequested in the onSessionStatusChanged function of your status listener. Please see this article for more information.

  7. In this case get IO2GSessionDescriptorCollection:

    IO2GSessionDescriptorCollection * descriptors = mSession->getTradingSessionDescriptors();
  8. Then process elements of this collection

  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:

    pSession->logout();
  12. Use the status listener onSessionStatusChanged function to capture the Disconnected event.

  13. Unsubscribe the session from the status listener:

    pSession->unsubscribeSessionStatus(sessionStatusListener);

See also the simplified login sequence diagram.

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

back