pub struct SessionApi { /* private fields */ }Expand description
Public entry point for session management. Obtain via
crate::IgClient::session.
Implementations§
Source§impl SessionApi
impl SessionApi
Sourcepub async fn login(&self) -> Result<SessionInfo>
pub async fn login(&self) -> Result<SessionInfo>
Log in using the canonical v3 flow (OAuth bearer tokens).
Sourcepub async fn login_with_encryption(&self) -> Result<SessionInfo>
Available on crate feature encryption only.
pub async fn login_with_encryption(&self) -> Result<SessionInfo>
encryption only.Log in v3 with an RSA-encrypted password instead of plaintext.
Recommended for accounts that hold real funds (live or funded demo). The password is encrypted client-side with IG’s published RSA public key (PKCS#1 v1.5) before being sent over the wire, so it never appears in plaintext in any intermediate proxy or server-side log.
Workflow (handled internally):
GET /session/encryptionKeyto fetch the public key + timestamp.encrypt_password(password, key, timestamp)(RSA PKCS#1v15).POST /sessionv3 withencryptedPassword=true.
Behind the optional encryption cargo feature.
§Errors
Error::Apiif either the key fetch or the login itself returns a non-2xx response.Error::Authif the encryption step fails (malformed key, bad key/timestamp combination, etc.).
Sourcepub async fn login_v2(&self) -> Result<SessionInfo>
pub async fn login_v2(&self) -> Result<SessionInfo>
Log in using the legacy v2 flow (CST + X-SECURITY-TOKEN response headers). Mainly used by the streaming client which still wants CST/XST.
Sourcepub async fn refresh(&self) -> Result<()>
pub async fn refresh(&self) -> Result<()>
Refresh the v3 access token using the stored refresh token.
Sourcepub async fn logout(&self) -> Result<()>
pub async fn logout(&self) -> Result<()>
Tear down the current session on the server side and locally.
Sourcepub async fn read(&self, fetch_tokens: bool) -> Result<SessionDetails>
pub async fn read(&self, fetch_tokens: bool) -> Result<SessionDetails>
Read details about the current session.
When fetch_tokens is true, the server responds with CST and
X-SECURITY-TOKEN headers. These are written into the local session
state — necessary when an OAuth (v3) session needs CST/XST tokens
for the Lightstreamer streaming endpoint.
Sourcepub async fn switch_account(
&self,
account_id: &str,
default_account: bool,
) -> Result<SwitchAccountResponse>
pub async fn switch_account( &self, account_id: &str, default_account: bool, ) -> Result<SwitchAccountResponse>
Switch the active trading account.
Updates the local session state so that subsequent v3 requests carry
the new IG-ACCOUNT-ID header.
Sourcepub async fn encryption_key(&self) -> Result<EncryptionKey>
Available on crate feature encryption only.
pub async fn encryption_key(&self) -> Result<EncryptionKey>
encryption only.Fetch the encryption key + timestamp used for encrypted-password login.
Combine with crate::session::encryption::encrypt_password (behind
the encryption feature) to build the password field expected by
POST /session when encryptedPassword=true.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SessionApi
impl !RefUnwindSafe for SessionApi
impl Send for SessionApi
impl Sync for SessionApi
impl Unpin for SessionApi
impl UnsafeUnpin for SessionApi
impl !UnwindSafe for SessionApi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more