How to log in
Brief
The article explains how to log in step by step.
Details
To log in, you should:
Implement the IO2GSessionStatus
interface in a status listener class:
class CSessionStatusListener : public IO2GSessionStatus {...}
Create a session
:
IO2GSession *pSession = CO2GTransport::createSession();
Create an instance of the session status listener:
CSessionStatusListener *sessionStatusListener = new CSessionStatusListener(&log, pSession, &oLoginData);
Subscribe the status listener
object to the session status.
It is important to subscribe before the login:
pSession->subscribeSessionStatus(sessionStatusListener);
The events are coming asynchronously. They should come in another thread.
When an event comes, a signal will be sent to the main thread.
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.
In this case get IO2GSessionDescriptorCollection:
IO2GSessionDescriptorCollection * descriptors = mSession->getTradingSessionDescriptors();
Then process elements of this collection
Finally set a trading session
using the session Id and pin:
mSession->setTradingSession("sessionID", "pin");
Use the status listener onSessionStatusChanged
function
to capture the Connected
event.
Log out
when you are done:
pSession->logout();
Use the status listener onSessionStatusChanged
function
to capture the Disconnected
event.
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.