pub trait IgAuthenticator: Send + Sync {
// Required methods
fn login<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn refresh<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn login_and_switch_account<'life0, 'life1, 'async_trait>(
&'life0 self,
account_id: &'life1 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn relogin_and_switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn relogin<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Trait for authenticating with the IG Markets API
Required Methods§
Sourcefn login<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn login<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Logs in to the IG Markets API and returns a new session
Sourcefn refresh<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn refresh<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Refreshes an existing session with the IG Markets API
Sourcefn switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn login_and_switch_account<'life0, 'life1, 'async_trait>(
&'life0 self,
account_id: &'life1 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn login_and_switch_account<'life0, 'life1, 'async_trait>(
&'life0 self,
account_id: &'life1 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Attempts to login and switch to the specified account, optionally setting it as the default account.
§Arguments
account_id- A string slice that holds the ID of the account to which the session should switch.default_account- An optional boolean parameter. IfSome(true), the given account will be marked as the default account for subsequent operations. IfNoneorSome(false), the account will not be set as default.
§Returns
This function returns a Result:
Ok(IgSession)- On success, contains an updatedIgSessionobject representing the active session state after the switch.Err(AuthError)- If the operation fails, returns anAuthErrorcontaining details about the issue.
§Errors
This function can return AuthError in the following scenarios:
- If the provided
account_idis invalid or does not exist. - If there is a network issue during the login/switch process.
- If there are authentication or session-related failures.
§Notes
Ensure that the account_id is valid and accessible under the authenticated user’s account scope.
Switching accounts may invalidate the previous session if the platform enforces single-session
restrictions.
Sourcefn relogin_and_switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn relogin_and_switch_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
account_id: &'life2 str,
default_account: Option<bool>,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Attempts to relogin (if needed) and switch to the specified account. This method uses relogin() instead of login() to avoid unnecessary authentication when tokens are still valid.
§Arguments
session- The current session to check for token validityaccount_id- The ID of the account to switch todefault_account- Whether to set this account as the default (optional)
§Returns
Ok(IgSession)- On success, contains an updated session for the target accountErr(AuthError)- If the operation fails
Sourcefn relogin<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn relogin<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 IgSession,
) -> Pin<Box<dyn Future<Output = Result<IgSession, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Re-authenticates only if the current session tokens are expired or close to expiring. This method checks the token expiration with a safety margin and only performs login if necessary, making it more efficient than always calling login().
§Arguments
session- The current session to check for token validity
§Returns
Ok(IgSession)- Either the existing session (if tokens are still valid) or a new session (if re-login was needed)Err(AuthError)- If re-authentication fails