pub struct HttpClient { /* private fields */ }Expand description
Simplified client for IG Markets API with automatic authentication
This client handles all authentication complexity internally, including:
- Initial login
- OAuth token refresh
- Re-authentication when tokens expire
- Account switching
- Rate limiting for all API requests
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub async fn new(config: Config) -> Result<Self, AppError>
pub async fn new(config: Config) -> Result<Self, AppError>
Creates a new client and performs initial authentication
§Arguments
config- Configuration containing credentials and API settings
§Returns
Ok(Client)- Authenticated client ready to useErr(AppError)- If authentication fails
§Errors
Returns AppError::Network if the underlying reqwest client cannot
be built (e.g. the system TLS backend fails to initialize), or any
AppError surfaced by the initial Auth::login call.
Sourcepub fn new_lazy(config: Config) -> Result<Self, AppError>
pub fn new_lazy(config: Config) -> Result<Self, AppError>
Creates a new client without performing initial authentication
§Errors
Returns AppError::Network if the HTTP client cannot be constructed.
Sourcepub async fn ws_info(&self) -> Result<WebsocketInfo, AppError>
pub async fn ws_info(&self) -> Result<WebsocketInfo, AppError>
Gets WebSocket connection information for Lightstreamer, reusing the cached session.
Delegates to Auth::ws_info, which returns the cached session when it
is valid and only logs in when needed.
§Returns
Ok(WebsocketInfo)- Server endpoint, authentication tokens, and account ID for the current session.Err(AppError)- If session retrieval (login / refresh) fails.
§Errors
Returns AppError when the session cannot be retrieved.
Sourcepub async fn get_ws_info(&self) -> WebsocketInfo
👎Deprecated: use ws_info() which reuses the cached session and returns a typed error instead of a default-on-error WebsocketInfo
pub async fn get_ws_info(&self) -> WebsocketInfo
use ws_info() which reuses the cached session and returns a typed error instead of a default-on-error WebsocketInfo
Gets WebSocket connection information for Lightstreamer
§Returns
WebsocketInfocontaining server endpoint, authentication tokens, and account ID
Sourcepub async fn get<T: DeserializeOwned>(
&self,
path: &str,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn get<T: DeserializeOwned>( &self, path: &str, version: Option<u8>, ) -> Result<T, AppError>
Makes a GET request
Sourcepub async fn post<B: Serialize, T: DeserializeOwned>(
&self,
path: &str,
body: B,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn post<B: Serialize, T: DeserializeOwned>( &self, path: &str, body: B, version: Option<u8>, ) -> Result<T, AppError>
Makes a POST request
Sourcepub async fn put<B: Serialize, T: DeserializeOwned>(
&self,
path: &str,
body: B,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn put<B: Serialize, T: DeserializeOwned>( &self, path: &str, body: B, version: Option<u8>, ) -> Result<T, AppError>
Makes a PUT request
Sourcepub async fn delete<T: DeserializeOwned>(
&self,
path: &str,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn delete<T: DeserializeOwned>( &self, path: &str, version: Option<u8>, ) -> Result<T, AppError>
Makes a DELETE request
Sourcepub async fn post_with_delete_method<B: Serialize, T: DeserializeOwned>(
&self,
path: &str,
body: B,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn post_with_delete_method<B: Serialize, T: DeserializeOwned>( &self, path: &str, body: B, version: Option<u8>, ) -> Result<T, AppError>
Makes a POST request with _method: DELETE header
This is required by IG API for closing positions, as they don’t support DELETE requests with a body. Instead, they use POST with a special header.
§Arguments
path- API endpoint pathbody- Request body to sendversion- API version to use
§Returns
Deserialized response of type T
Sourcepub async fn request<B: Serialize, T: DeserializeOwned>(
&self,
method: Method,
path: &str,
body: Option<B>,
version: Option<u8>,
) -> Result<T, AppError>
pub async fn request<B: Serialize, T: DeserializeOwned>( &self, method: Method, path: &str, body: Option<B>, version: Option<u8>, ) -> Result<T, AppError>
Makes a request with custom API version
Sourcepub async fn switch_account(
&self,
account_id: &str,
default_account: Option<bool>,
) -> Result<(), AppError>
pub async fn switch_account( &self, account_id: &str, default_account: Option<bool>, ) -> Result<(), AppError>
Switches to a different trading account
Sourcepub async fn get_session(&self) -> Result<Session, AppError>
pub async fn get_session(&self) -> Result<Session, AppError>
Gets the current session
Auto Trait Implementations§
impl !RefUnwindSafe for HttpClient
impl !UnwindSafe for HttpClient
impl Freeze for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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