ig_client/session/interface.rs
1use crate::error::AuthError;
2
3/// Session information for IG Markets API authentication
4#[derive(Debug, Clone)]
5pub struct IgSession {
6 /// Client Session Token (CST) used for authentication
7 pub cst: String,
8 /// Security token used for authentication
9 pub token: String,
10 /// Account ID associated with the session
11 pub account_id: String,
12}
13
14/// Trait for authenticating with the IG Markets API
15#[async_trait::async_trait]
16pub trait IgAuthenticator: Send + Sync {
17 /// Logs in to the IG Markets API and returns a new session
18 async fn login(&self) -> Result<IgSession, AuthError>;
19 /// Refreshes an existing session with the IG Markets API
20 async fn refresh(&self, session: &IgSession) -> Result<IgSession, AuthError>;
21 /// Switches the active account for the current session
22 ///
23 /// # Arguments
24 /// * `session` - The current session
25 /// * `account_id` - The ID of the account to switch to
26 /// * `default_account` - Whether to set this account as the default (optional)
27 ///
28 /// # Returns
29 /// * A new session with the updated account ID
30 async fn switch_account(
31 &self,
32 session: &IgSession,
33 account_id: &str,
34 default_account: Option<bool>,
35 ) -> Result<IgSession, AuthError>;
36}