-
Notifications
You must be signed in to change notification settings - Fork 3
Session
To interact with Betfair you need to retrieve and pass a valid session token on every request. Use the Session class to manage your session and token.
Before you get started you will need a valid Betfair AppKey and account. Pass your AppKey, Username and Password into the Session constructor. If any of these values are null or empty you will receive an ArgumentNullException.
var session = new Session("AppKey", "Username", "Password");
Get a Session Token:
var token = await session.GetSessionTokenAsync();
By default each session token will expire after 8 hours. This default can be can be changed by setting the SessionTimeout property. Make sure this setting matches the setting in your Betfair account, which can be found in Betfair -> My Account -> Security Settings and is also defaulted to 8 hours.
session.SessionTimeout = TimeSpan.FromHours(5);
The exact time that your session token will expire can be checked using the SessionExpiryTime property.
var sessionExpiryTime = session.SessionExpiryTime;
GetSessionTokenAsync will automatically handle calls to the appropriate Betfair endpoints of Login and KeepAlive. GetSessionTokenAsync will call Login if the current session is invalid or expired and call KeepAlive if the session is about to expire. By default KeepAlive will be called if the current session is due to expire within the next hour.