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
impl IgClient
Sourcepub fn new(config: ClientConfig) -> IgResult<Self>
pub fn new(config: ClientConfig) -> IgResult<Self>
Constructs a client without contacting IG.
Sourcepub async fn login(&self) -> IgResult<LoginResponse>
pub async fn login(&self) -> IgResult<LoginResponse>
Authenticates using the protocol selected in ClientConfig::authentication.
Sourcepub async fn login_v2(&self) -> IgResult<LoginResponse>
pub async fn login_v2(&self) -> IgResult<LoginResponse>
Authenticates with v2 and stores the CST/X-SECURITY-TOKEN pair.
Sourcepub async fn login_v3(&self, account_id: &str) -> IgResult<LoginResponse>
pub async fn login_v3(&self, account_id: &str) -> IgResult<LoginResponse>
Authenticates with v3 OAuth and stores refreshable bearer credentials.
Sourcepub async fn logout(&self) -> IgResult<()>
pub async fn logout(&self) -> IgResult<()>
Deletes the current session and clears local tokens only after IG accepts the request.
Sourcepub async fn accounts(&self) -> IgResult<AccountsResponse>
pub async fn accounts(&self) -> IgResult<AccountsResponse>
Returns the accounts available to the authenticated client.
Sourcepub async fn switch_account(
&self,
account_id: &str,
) -> IgResult<SwitchAccountResponse>
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.
Sourcepub async fn positions(&self) -> IgResult<PositionsResponse>
pub async fn positions(&self) -> IgResult<PositionsResponse>
Returns all open positions for the active account.
Sourcepub async fn market(&self, epic: &str) -> IgResult<MarketDetails>
pub async fn market(&self, epic: &str) -> IgResult<MarketDetails>
Returns market metadata and a latest price snapshot for one IG epic.
Sourcepub async fn search_markets(&self, query: &str) -> IgResult<MarketsResponse>
pub async fn search_markets(&self, query: &str) -> IgResult<MarketsResponse>
Searches the market catalogue using IG’s /markets endpoint.
Sourcepub async fn historical_prices(
&self,
epic: &str,
query: HistoricalPricesQuery<'_>,
) -> IgResult<HistoricalPricesResponse>
pub async fn historical_prices( &self, epic: &str, query: HistoricalPricesQuery<'_>, ) -> IgResult<HistoricalPricesResponse>
Returns historical prices for an epic at the requested IG resolution.
Sourcepub async fn create_position(
&self,
request: &CreatePositionRequest,
) -> IgResult<DealReferenceResponse>
pub async fn create_position( &self, request: &CreatePositionRequest, ) -> IgResult<DealReferenceResponse>
Creates a position. This operation is never automatically retried.
Sourcepub async fn deal_confirmation(
&self,
deal_reference: &str,
) -> IgResult<DealConfirmation>
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.
Sourcepub async fn working_orders(&self) -> IgResult<WorkingOrdersResponse>
pub async fn working_orders(&self) -> IgResult<WorkingOrdersResponse>
Returns every working order for the active account.
Sourcepub async fn create_working_order(
&self,
request: &CreateWorkingOrderRequest,
) -> IgResult<DealReferenceResponse>
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.
Sourcepub async fn update_working_order(
&self,
deal_id: &str,
request: &UpdateWorkingOrderRequest,
) -> IgResult<DealReferenceResponse>
pub async fn update_working_order( &self, deal_id: &str, request: &UpdateWorkingOrderRequest, ) -> IgResult<DealReferenceResponse>
Updates an existing working order. Writes are never automatically replayed.
Sourcepub async fn delete_working_order(
&self,
deal_id: &str,
) -> IgResult<DealReferenceResponse>
pub async fn delete_working_order( &self, deal_id: &str, ) -> IgResult<DealReferenceResponse>
Deletes an existing working order. Writes are never automatically replayed.
Sourcepub async fn connect_streaming(&self) -> IgResult<IgStreamingClient>
pub async fn connect_streaming(&self) -> IgResult<IgStreamingClient>
Opens IG’s Lightstreamer endpoint using credentials issued by v2 login.