Every call to the Forex.com / StoneX / CityIndex Trading API requires an active session. Session state is obtained with LogOn, ended with LogOff, and kept alive with Ping.
Set the credentials on the main client component. They are copied into the REST session on the first call.
| Method | Parameters | Description |
| LogOn | UserName, Password, AppKey | Opens a REST session. Returns the full JSON response and stores SessionToken, ClientAccountId and TradingAccountId on the main client. All later REST and streaming calls authenticate with that token. |
| LogOff | Invalidates the session on the server and clears the token. | |
| Ping | Keeps the session alive. The server session expires after a period of inactivity; issue Ping periodically when no other REST call is being made. | |
| GetServiceStatus | Reports the current service status (no authentication required). |
The token returned by LogOn is attached to every subsequent REST request as the UserName HTTP header. The same token is reused by the streaming client as the LS_password field when the Lightstreamer session is created. There is no need to call LogOn twice: calling Connect on the main client performs the REST LogOn first and only then opens the streaming socket.
Open a REST session and call Ping
oForex := TsgcWSAPI_Forex.Create(nil);
oForex.Credentials.UserName := '<username>';
oForex.Credentials.Password := '<password>';
oForex.Credentials.AppKey := '<appkey>';
// explicit REST-only usage
ShowMessage(oForex.REST_API.LogOn(oForex.Credentials.UserName,
oForex.Credentials.Password,
oForex.Credentials.AppKey));
ShowMessage(oForex.REST_API.Ping);
oForex.REST_API.LogOff;