Skip to main content

IgClient

Struct IgClient 

Source
pub struct IgClient { /* private fields */ }
Expand description

IG REST trading client.

Session credentials are kept behind a lock so that one client can be shared among concurrent read-only tasks after Self::login succeeds. Calls which change server state are deliberately made once and are never automatically replayed.

Implementations§

Source§

impl IgClient

Source

pub fn new(config: ClientConfig) -> IgResult<Self>

Constructs a client without contacting IG.

Source

pub async fn login(&self) -> IgResult<LoginResponse>

Authenticates using the protocol selected in ClientConfig::authentication.

Source

pub async fn login_v2(&self) -> IgResult<LoginResponse>

Authenticates with v2 and stores the CST/X-SECURITY-TOKEN pair.

Source

pub async fn login_v3(&self, account_id: &str) -> IgResult<LoginResponse>

Authenticates with v3 OAuth and stores refreshable bearer credentials.

Source

pub async fn logout(&self) -> IgResult<()>

Deletes the current session and clears local tokens only after IG accepts the request.

Source

pub async fn accounts(&self) -> IgResult<AccountsResponse>

Returns the accounts available to the authenticated client.

Source

pub async fn switch_account( &self, account_id: &str, ) -> IgResult<SwitchAccountResponse>

Switches the active V2 account without changing the user’s default.

IG rotates the X-SECURITY-TOKEN when the active account changes. The returned header is committed atomically with the local account ID so subsequent REST and Lightstreamer calls cannot retain the old account token.

Source

pub async fn positions(&self) -> IgResult<PositionsResponse>

Returns all open positions for the active account.

Source

pub async fn market(&self, epic: &str) -> IgResult<MarketDetails>

Returns market metadata and a latest price snapshot for one IG epic.

Source

pub async fn search_markets(&self, query: &str) -> IgResult<MarketsResponse>

Searches the market catalogue using IG’s /markets endpoint.

Source

pub async fn historical_prices( &self, epic: &str, query: HistoricalPricesQuery<'_>, ) -> IgResult<HistoricalPricesResponse>

Returns historical prices for an epic at the requested IG resolution.

Source

pub async fn create_position( &self, request: &CreatePositionRequest, ) -> IgResult<DealReferenceResponse>

Creates a position. This operation is never automatically retried.

Source

pub async fn deal_confirmation( &self, deal_reference: &str, ) -> IgResult<DealConfirmation>

Resolves a submission acknowledgement into IG’s authoritative deal confirmation. Callers must not treat the initial deal reference as an accepted order.

Source

pub async fn working_orders(&self) -> IgResult<WorkingOrdersResponse>

Returns every working order for the active account.

Source

pub async fn create_working_order( &self, request: &CreateWorkingOrderRequest, ) -> IgResult<DealReferenceResponse>

Creates a working order. Resolve the returned reference with Self::deal_confirmation before treating it as accepted.

Source

pub async fn update_working_order( &self, deal_id: &str, request: &UpdateWorkingOrderRequest, ) -> IgResult<DealReferenceResponse>

Updates an existing working order. Writes are never automatically replayed.

Source

pub async fn delete_working_order( &self, deal_id: &str, ) -> IgResult<DealReferenceResponse>

Deletes an existing working order. Writes are never automatically replayed.

Source

pub async fn connect_streaming(&self) -> IgResult<IgStreamingClient>

Opens IG’s Lightstreamer endpoint using credentials issued by v2 login.

Trait Implementations§

Source§

impl Debug for IgClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more