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 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.