Broker API HubMenu

IG API POST /indicativecostsandcharges/close

POST/indicativecostsandcharges/closeversion 1Costs and charges

Ask for an indicative breakdown of the costs and charges of closing an open deal. Nothing is traded.

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.

Independent and unofficiallabs.ig.comchecked

The method, path, version, parameters and response fields were 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 page limits the call to a list of IG website identifiers, so it may not answer for every account. Required is recorded for the fields the page marks as not null.

Parameters

NameInTypeDescription
VERSIONrequiredheaderstringEndpoint version. Send 1.
askrequiredbodynumberCurrent ask price of the market.
bidrequiredbodynumberCurrent bid price of the market.
dealCurrencyCoderequiredbodystringCurrency the deal is in.
dealReferencerequiredbodystringYour reference for the deal the quote is for.
sizerequiredbodynumberDeal size.
directionbodystringBUY or SELL.
epicbodystringInstrument epic.
instrumentIdbodystringInstrument identifier.
guaranteedStopbodybooleanTrue where the deal carries a guaranteed stop.
knockoutPremiumbodynumberKnockout premium, for knockout products.
priceLevelbodynumberPrice level of the deal.
stopLevelbodynumberStop level.
openingLevelrequiredbodynumberLevel the deal was opened at.

Authentication headers

NameTypeDescription
X-IG-API-KEYrequiredstringYour API key, from your IG account settings. Placeholder only here.
CSTrequiredstringClient session token returned by POST /session.
X-SECURITY-TOKENrequiredstringAccount 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. 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.
# Optional and not shown: body fields direction, epic, instrumentId, guaranteedStop, knockoutPremium, priceLevel, stopLevel.
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": "1",
}
body = {"ask": 0, "bid": 0, "dealCurrencyCode": "...", "dealReference": "...", "size": 0, "openingLevel": 0}
resp = requests.post(BASE_URL + "/indicativecostsandcharges/close", 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.
// Optional and not shown: body fields direction, epic, instrumentId, guaranteedStop, knockoutPremium, priceLevel, stopLevel.
// 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 + "/indicativecostsandcharges/close", {
  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": "1",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"ask": 0, "bid": 0, "dealCurrencyCode": "...", "dealReference": "...", "size": 0, "openingLevel": 0}),
});
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.
# Optional and not shown: body fields direction, epic, instrumentId, guaranteedStop, knockoutPremium, priceLevel, stopLevel.
curl -X POST "https://demo-api.ig.com/gateway/deal/indicativecostsandcharges/close" \
  -H "X-IG-API-KEY: $IG_API_KEY" \
  -H "CST: $IG_CST" \
  -H "X-SECURITY-TOKEN: $IG_SECURITY_TOKEN" \
  -H "VERSION: 1" \
  -H "Content-Type: application/json" \
  -d '{"ask": 0, "bid": 0, "dealCurrencyCode": "...", "dealReference": "...", "size": 0, "openingLevel": 0}'

Response

A mock response. The values are invented, so check field names against the official reference.

{
  "_mock": true,
  "close": {
    "indicativeQuoteReference": "MOCKQUOTE2",
    "notionalValue": 7650,
    "closingSpread": 1,
    "closingCommission": 0,
    "closingFxFee": 0,
    "guaranteedStopReturn": 0
  },
  "currencyCodeISO": "GBP"
}

Limits that apply at IG

LimitValueScopeSource
Historical price data points a week10,000Per account, price history endpoints onlylabs.ig.comchecked
Non trading requests a minute30Per account, non trading calls onlylabs.ig.comchecked
Non trading requests a minute60Per application, that is per API key, non trading calls onlylabs.ig.comchecked
Concurrent streaming subscriptions40Per streaming connectionlabs.ig.comchecked corroborated by labs.ig.com/streaming-api-guide.html
Trading requests a minute100Sources 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 onlylabs.ig.comchecked

IG API errors you may meet

All IG API error codes, including 126 more not listed here.