IG API POST /positions/otc
Open an OTC position. Returns a dealReference only: the deal is not confirmed until you call GET /confirms/{dealReference}.
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. Required is recorded for the fields the page marks as not null. The page does not mark direction or orderType as not null: that describes the page, not a test of what the host accepts. The page also lists an optional dealReference body field, which is not recorded here.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| VERSIONrequired | header | string | Endpoint version. Send 2. |
| epicrequired | body | string | Instrument epic, for example IX.D.FTSE.DAILY.IP. |
| directionnot marked by the vendor | body | string | BUY or SELL. |
| sizerequired | body | number | Deal size. |
| orderTypenot marked by the vendor | body | string | MARKET, LIMIT or QUOTE. |
| expiryrequired | body | string | "DFB" for daily funded spread bets, "-" for CFDs, or a contract month for futures style bets. |
| currencyCoderequired | body | string | Currency, for example GBP. |
| forceOpenrequired | body | boolean | True to open a new position rather than net against an opposite one. |
| guaranteedStoprequired | body | boolean | True for a guaranteed stop. |
| level | body | number | Price level for LIMIT or QUOTE orders. |
| stopDistance | body | number | Stop distance in points. |
| limitDistance | body | number | Limit distance in points. |
| trailingStop | body | boolean | True for a trailing stop. |
| limitLevel | body | number | Limit as a price level, instead of limitDistance. |
| stopLevel | body | number | Stop as a price level, instead of stopDistance. |
| quoteId | body | string | Quote ID, for orderType QUOTE. |
| timeInForce | body | string | Optional time in force for the order. |
| trailingStopIncrement | body | number | Trailing stop increment, used with trailingStop. |
2 fields are tagged not marked by the vendor: direction, orderType. The vendor's page lists them and marks them neither required nor optional. That describes the page, not a test of what the host accepts, so the samples send them with a placeholder.
Authentication headers
| Name | Type | Description |
|---|---|---|
| X-IG-API-KEYrequired | string | Your API key, from your IG account settings. Placeholder only here. |
| CSTrequired | string | Client session token returned by POST /session. |
| X-SECURITY-TOKENrequired | string | Account security token returned by POST /session. |
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 6 body fields the record marks as required, and a placeholder for each of the 2 body fields the vendor's page marks neither required nor optional, named in the sample's own comment. Each placeholder has to be replaced with a real value before the request can succeed.
Python
# Set IG_API_KEY, IG_CST, IG_SECURITY_TOKEN as environment variables first. Never paste real values into code.
# IG_CST and IG_SECURITY_TOKEN hold the CST and X-SECURITY-TOKEN headers that POST /session returns: step 3 of the quickstart (/brokers/ig/quickstart#step-3) captures them and this sample reads them back.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Not marked required or optional on the vendor's page, so sent here with a placeholder: direction, orderType. Leave out any the call does not need.
# Optional and not shown: body fields level, stopDistance, limitDistance, trailingStop, limitLevel, stopLevel, quoteId, timeInForce, trailingStopIncrement.
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"],
"CST": os.environ["IG_CST"],
"X-SECURITY-TOKEN": os.environ["IG_SECURITY_TOKEN"],
"VERSION": "2",
}
body = {"epic": "...", "direction": "...", "size": 0, "orderType": "...", "expiry": "...", "currencyCode": "...", "forceOpen": False, "guaranteedStop": False}
resp = requests.post(BASE_URL + "/positions/otc", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set IG_API_KEY, IG_CST, IG_SECURITY_TOKEN as environment variables first. Never paste real values into code.
// IG_CST and IG_SECURITY_TOKEN hold the CST and X-SECURITY-TOKEN headers that POST /session returns: step 3 of the quickstart (/brokers/ig/quickstart#step-3) captures them and this sample reads them back.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Not marked required or optional on the vendor's page, so sent here with a placeholder: direction, orderType. Leave out any the call does not need.
// Optional and not shown: body fields level, stopDistance, limitDistance, trailingStop, limitLevel, stopLevel, quoteId, timeInForce, trailingStopIncrement.
// 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 + "/positions/otc", {
method: "POST",
headers: {
"X-IG-API-KEY": process.env.IG_API_KEY,
"CST": process.env.IG_CST,
"X-SECURITY-TOKEN": process.env.IG_SECURITY_TOKEN,
"VERSION": "2",
"Content-Type": "application/json",
},
body: JSON.stringify({"epic": "...", "direction": "...", "size": 0, "orderType": "...", "expiry": "...", "currencyCode": "...", "forceOpen": false, "guaranteedStop": false}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set IG_API_KEY, IG_CST, IG_SECURITY_TOKEN as environment variables first. Never paste real values into code.
# IG_CST and IG_SECURITY_TOKEN hold the CST and X-SECURITY-TOKEN headers that POST /session returns: step 3 of the quickstart (/brokers/ig/quickstart#step-3) captures them and this sample reads them back.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Not marked required or optional on the vendor's page, so sent here with a placeholder: direction, orderType. Leave out any the call does not need.
# Optional and not shown: body fields level, stopDistance, limitDistance, trailingStop, limitLevel, stopLevel, quoteId, timeInForce, trailingStopIncrement.
curl -X POST "https://demo-api.ig.com/gateway/deal/positions/otc" \
-H "X-IG-API-KEY: $IG_API_KEY" \
-H "CST: $IG_CST" \
-H "X-SECURITY-TOKEN: $IG_SECURITY_TOKEN" \
-H "VERSION: 2" \
-H "Content-Type: application/json" \
-d '{"epic": "...", "direction": "...", "size": 0, "orderType": "...", "expiry": "...", "currencyCode": "...", "forceOpen": false, "guaranteedStop": false}'Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"dealReference": "MOCKREF0001"
}Response schema, HTTP 200
Every field this site's OpenAPI file for IG declares for this response.
| Field | Type | Description |
|---|---|---|
| dealReference | string | 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.account-access-deniedHTTP 401. The account has been denied login privileges.
- error.security.account-migratedHTTP 401. The account has been migrated to IG's client and account model.
- ACCOUNT_NOT_ENABLED_TO_TRADINGThe account is not enabled to trade.
- error.security.account-not-yet-activatedHTTP 401. The account has not been activated yet.
- error.security.account-suspendedHTTP 401. The account has been suspended.
- error.security.account-token-invalidHTTP 401. The endpoint needs an account token and the one sent was not valid.
All IG API error codes, including 126 more not listed here.