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 fn new_lazy(config: Config) -> Self
pub fn new_lazy(config: Config) -> Self
Creates a new client without performing initial authentication
Sourcepub async fn get_ws_info(&self) -> WebsocketInfo
pub async fn get_ws_info(&self) -> 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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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