IG API POST /session
Log in with username and password. Returns CST and X-SECURITY-TOKEN in the response headers; send both on every later call.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
The method, path, version and parameters were re-read on IG's own reference page on 12 Oct 2026. That page lists no request headers: the headers recorded here are the general ones in IG's REST trading API guide (labs.ig.com/rest-trading-api-guide.html), read the same day. The mock reply is carried over from an earlier reading and was not compared field by field with the page. IG's own Java sample (RestAPI.java on GitHub, read the same day and marked deprecated) uses the same path. The page marks identifier and password as required for version 2 and lists encryptedPassword as a flag. Version 3 also exists and returns OAuth tokens that expire after about a minute, a community figure from the trading-ig FAQ; IG Labs' own FAQ gives 12 hours between calls for the v2 CST and X-SECURITY-TOKEN pair, while IG's REST trading API guide says 6 hours at first, extended up to a maximum of 72 hours: two IG pages that disagree.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| VERSIONrequired | header | string | Endpoint version. Send 2. |
| identifierrequired | body | string | Your IG username (not your email). |
| passwordrequired | body | string | Your IG password. Never paste it into this site. |
| encryptedPassword | body | boolean | Optional. Leave it out, or send false, when you send your password as plain text over HTTPS. Send true only if you encrypted the password with the key from GET /session/encryptionKey. |
Authentication headers
| Name | Type | Description |
|---|---|---|
| X-IG-API-KEYrequired | string | Your API key. Placeholder only. |
Request
Written from the method, path and parameters recorded on this page, against the demo host. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.
This call takes a request body. The samples send it as JSON with a Content-Type of application/json (in Python, passing json= sets that header) and a placeholder for each of the 2 body fields the record marks as required. Each placeholder has to be replaced with a real value before the request can succeed.
Python
# Set IG_API_KEY, IG_USERNAME, IG_PASSWORD as environment variables first. Never paste real values into code.
# Optional and not shown: body fields encryptedPassword.
import os
import requests
BASE_URL = "https://demo-api.ig.com/gateway/deal" # the demo host
headers = {
"X-IG-API-KEY": os.environ["IG_API_KEY"],
"VERSION": "2",
}
body = {"identifier": os.environ["IG_USERNAME"], "password": os.environ["IG_PASSWORD"]}
resp = requests.post(BASE_URL + "/session", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set IG_API_KEY, IG_USERNAME, IG_PASSWORD as environment variables first. Never paste real values into code.
// Optional and not shown: body fields encryptedPassword.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = "https://demo-api.ig.com/gateway/deal"; // the demo host
const res = await fetch(BASE_URL + "/session", {
method: "POST",
headers: {
"X-IG-API-KEY": process.env.IG_API_KEY,
"VERSION": "2",
"Content-Type": "application/json",
},
body: JSON.stringify({"identifier": process.env.IG_USERNAME, "password": process.env.IG_PASSWORD}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set IG_API_KEY, IG_USERNAME, IG_PASSWORD as environment variables first. Never paste real values into code.
# Optional and not shown: body fields encryptedPassword.
curl -X POST "https://demo-api.ig.com/gateway/deal/session" \
-H "X-IG-API-KEY: $IG_API_KEY" \
-H "VERSION: 2" \
-H "Content-Type: application/json" \
-d "{\"identifier\": \"$IG_USERNAME\", \"password\": \"$IG_PASSWORD\"}"Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"accountType": "SPREADBET",
"currencyIsoCode": "GBP",
"currentAccountId": "MOCK123",
"lightstreamerEndpoint": "https://mock-apd.marketdatasystems.example",
"clientId": "000000",
"timezoneOffset": 1
}Response schema, HTTP 200
Every field this site's OpenAPI file for IG declares for this response.
| Field | Type | Description |
|---|---|---|
| accountType | string | Not recorded |
| currencyIsoCode | string | Not recorded |
| currentAccountId | string | Not recorded |
| lightstreamerEndpoint | string | Not recorded |
| clientId | string | Not recorded |
| timezoneOffset | number | Not recorded |
Unverifiedchecked no source opened This schema is not sourced to a page of the provider's own that we opened, so check field names against the official reference.
Limits that apply at IG
| Limit | Value | Scope | Source |
|---|---|---|---|
| Historical price data points a week | 10,000 | Per account, price history endpoints only | labs.ig.comchecked |
| Non trading requests a minute | 30 | Per account, non trading calls only | labs.ig.comchecked |
| Non trading requests a minute | 60 | Per application, that is per API key, non trading calls only | labs.ig.comchecked |
| Concurrent streaming subscriptions | 40 | Per streaming connection | labs.ig.comchecked corroborated by labs.ig.com/streaming-api-guide.html |
| Trading requests a minute | 100Sources conflict ig.com states around 40, checked . IG's own pages disagree. The conflict is labelled, not resolved. Pace against 40. | Per account, trading calls only | labs.ig.comchecked |
IG API errors you may meet
- error.security.api-key-invalidHTTP 403. The API key provided was not accepted.
- error.public-api.failure.encryption.requiredHTTP 400. A login was sent to version 1 of the session endpoint by a client of the IG Singapore company.
- error.public-api.exceeded-account-allowanceHTTP 403. The account's traffic allowance has been exceeded.
- error.public-api.exceeded-account-historical-data-allowanceHTTP 403. The account's allowance for historical data has been exceeded.
- error.public-api.exceeded-account-trading-allowanceHTTP 403. The account's allowance for trading requests has been exceeded.
- error.public-api.exceeded-api-key-allowanceHTTP 403. The traffic allowance of the API key has been exceeded.
All IG API error codes, including 126 more not listed here.