IgAuthenticator

Trait IgAuthenticator 

Source
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§

Source

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

Source

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

Source

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,

Switches the active account for the current session

§Arguments
  • session - The current session
  • account_id - The ID of the account to switch to
  • default_account - Whether to set this account as the default (optional)
§Returns
  • A new session with the updated account ID
Source

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. If Some(true), the given account will be marked as the default account for subsequent operations. If None or Some(false), the account will not be set as default.
§Returns

This function returns a Result:

  • Ok(IgSession) - On success, contains an updated IgSession object representing the active session state after the switch.
  • Err(AuthError) - If the operation fails, returns an AuthError containing details about the issue.
§Errors

This function can return AuthError in the following scenarios:

  • If the provided account_id is 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.

Source

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 validity
  • account_id - The ID of the account to switch to
  • default_account - Whether to set this account as the default (optional)
§Returns
  • Ok(IgSession) - On success, contains an updated session for the target account
  • Err(AuthError) - If the operation fails
Source

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

Implementors§