While the connection is up you should receive packets at least every five seconds, either data packets or heartbeats ("PROBE" packets). If you don't, something is wrong.
The REST API is stateless and doesn't really maintain a session other than to keep track of CST and X-SECURITY-TOKEN tokens and invalidating them after a certain amount of time. We currently don't provide a REST endpoint to indicate whether the security tokens are still valid. The API will return a 401 invalid token failure if the tokens have expired.
If the rest api is stateless then do not expire the token,
if you do expire the token then provide a heartbeat function, which can check the validity, so the live trading algo does not run into an authentication error. Ideally, the heartbeat function also reset the timeout/expiration period.
The API is a stateless REST API, so a heart beat is not possible. You can login at any point and obtain new tokens. A periodic thread could run in the background hitting an endpoint looking for the 401 error code with the message for an invalid account or client token and then call the login endpoint again. So either testing that the session tokens are still valid as described or automatically login again after having held the tokens for a few hours are two possible solutions.
While the connection is up you should receive packets at least every five seconds, either data packets or heartbeats ("PROBE" packets). If you don't, something is wrong.
Subscribe to any price stream.
The client libraries also have failure events that you can listen to.
How is it possible to check the rest api session is alive/valid?
Is there a heartbeat function that can be called every 10-20-30 sec?
Hi Jim,
Heartbeat for LS connections are discussed here: http://labs.ig.com/node/241
The REST API is stateless and doesn't really maintain a session other than to keep track of CST and X-SECURITY-TOKEN tokens and invalidating them after a certain amount of time. We currently don't provide a REST endpoint to indicate whether the security tokens are still valid. The API will return a 401 invalid token failure if the tokens have expired.
Hope that helps.
Chris
Hello Chris,
If the rest api is stateless then do not expire the token,
if you do expire the token then provide a heartbeat function, which can check the validity, so the live trading algo does not run into an authentication error. Ideally, the heartbeat function also reset the timeout/expiration period.
Regards,
Jim
Hi Jim,
The API is a stateless REST API, so a heart beat is not possible. You can login at any point and obtain new tokens. A periodic thread could run in the background hitting an endpoint looking for the 401 error code with the message for an invalid account or client token and then call the login endpoint again. So either testing that the session tokens are still valid as described or automatically login again after having held the tokens for a few hours are two possible solutions.
Hope that helps.
Chris