pub struct IgSession {
pub cst: String,
pub token: String,
pub oauth_token: Option<OAuthToken>,
pub account_id: String,
pub base_url: String,
pub client_id: String,
pub lightstreamer_endpoint: String,
pub api_key: String,
pub token_timer: Arc<Mutex<TokenTimer>>,
/* private fields */
}Expand description
Session information for IG Markets API authentication
Supports both API v2 (CST/X-SECURITY-TOKEN) and v3 (OAuth) authentication.
Fields§
§cst: StringClient Session Token (CST) used for authentication (API v2)
token: StringSecurity token used for authentication (API v2)
oauth_token: Option<OAuthToken>OAuth token information (API v3)
account_id: StringAccount ID associated with the session
base_url: StringBase URL for API requests
client_id: StringClient ID for API requests
lightstreamer_endpoint: StringLightstreamer endpoint for API requests
api_key: StringAPI key for API requests
token_timer: Arc<Mutex<TokenTimer>>Timer for managing token expiration and automatic refresh cycles
Implementations§
Source§impl IgSession
impl IgSession
Sourcepub fn new(cst: String, token: String, account_id: String) -> Self
pub fn new(cst: String, token: String, account_id: String) -> Self
Creates a new session with the given credentials
This is a simplified version for tests and basic usage. Uses default values for most fields and a default rate limiter.
Sourcepub fn new_with_config(
base_url: String,
cst: String,
security_token: String,
client_id: String,
account_id: String,
lightstreamer_endpoint: String,
api_key: String,
rate_limit_type: RateLimitType,
rate_limit_safety_margin: f64,
) -> Self
pub fn new_with_config( base_url: String, cst: String, security_token: String, client_id: String, account_id: String, lightstreamer_endpoint: String, api_key: String, rate_limit_type: RateLimitType, rate_limit_safety_margin: f64, ) -> Self
Creates a new session with the given parameters
This creates a thread-safe session that can be shared across multiple threads. The rate limiter is wrapped in an Arc to ensure proper synchronization.
Sourcepub fn with_rate_limiter(
cst: String,
token: String,
account_id: String,
limit_type: RateLimitType,
) -> Self
pub fn with_rate_limiter( cst: String, token: String, account_id: String, limit_type: RateLimitType, ) -> Self
Creates a new session with the given credentials and a rate limiter
This creates a thread-safe session that can be shared across multiple threads.
Sourcepub fn from_config(
cst: String,
token: String,
account_id: String,
config: &Config,
) -> Self
pub fn from_config( cst: String, token: String, account_id: String, config: &Config, ) -> Self
Creates a new session with the given credentials and rate limiter configuration from Config
Sourcepub async fn respect_rate_limit(&self) -> Result<(), AppError>
pub async fn respect_rate_limit(&self) -> Result<(), AppError>
Waits if necessary to respect rate limits before making a request
This method will always use a rate limiter - either the one configured in the session, or a default one if none is configured.
This method is thread-safe and can be called from multiple threads concurrently.
§Returns
Ok(())- If the rate limit is respectedErr(AppError::RateLimitExceeded)- If the rate limit has been exceeded and cannot be respected
Sourcepub async fn get_rate_limit_stats(&self) -> Option<RateLimiterStats>
pub async fn get_rate_limit_stats(&self) -> Option<RateLimiterStats>
Gets statistics about the current rate limit usage
Sourcepub fn refresh_token_timer(&self)
pub fn refresh_token_timer(&self)
Refreshes the token timer to extend token validity This should be called after each successful API request
Sourcepub fn is_oauth(&self) -> bool
pub fn is_oauth(&self) -> bool
Checks if this session is using OAuth (API v3) authentication
§Returns
true if the session has OAuth tokens, false otherwise
Sourcepub fn is_cst_auth(&self) -> bool
pub fn is_cst_auth(&self) -> bool
Checks if this session is using CST/X-SECURITY-TOKEN (API v2) authentication
§Returns
true if the session uses CST tokens, false otherwise
Sourcepub fn from_oauth(
oauth_token: OAuthToken,
account_id: String,
client_id: String,
lightstreamer_endpoint: String,
config: &Config,
) -> Self
pub fn from_oauth( oauth_token: OAuthToken, account_id: String, client_id: String, lightstreamer_endpoint: String, config: &Config, ) -> Self
Creates a new session with OAuth authentication (API v3)
§Arguments
oauth_token- The OAuth token informationaccount_id- Account ID associated with the sessionclient_id- Client ID provided by the APIlightstreamer_endpoint- Lightstreamer endpoint for real-time dataconfig- Configuration for rate limiting
§Returns
A new IgSession configured for OAuth authentication
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IgSession
impl !RefUnwindSafe for IgSession
impl Send for IgSession
impl Sync for IgSession
impl Unpin for IgSession
impl !UnwindSafe for IgSession
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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