Broker API HubMenu

Capital.com API with Python

Capital.com publishes a REST API and a Postman collection, but no Python SDK of its own. That is fine: the API is plain enough that requests will do. The part that catches people is the setup.

Independent and unofficialLast reviewed

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.

Carried over from an earlier version of this site. The links below are the sources it was written from, but its statements have not been re-read at source since the date shown, so check anything you rely on.

What you need to know before you write a line

Capital.com's own repositories cover Postman, Java samples and an MCP server. No Python package is published by the broker, so the honest answer for Python is the requests library against the REST API.

Source: GitHub: capital-com-sv/capital-api-postman checked 18 Sep 2026

capitalcom-python on PyPI has had no release since 0.2.3 in December 2023. It may still work, but nobody is maintaining it, so read the code before you depend on it.

Source: PyPI: capitalcom-python checked 18 Sep 2026

POST /session with an X-CAP-API-KEY header plus your login credentials returns CST and X-SECURITY-TOKEN, which you send on every later call. The session expires after 10 minutes of inactivity.

Source: Capital.com Public API documentation checked 18 Sep 2026

demo-api-capital.backend-capital.com for demo and api-capital.backend-capital.com for live. Point a script at the wrong one and the credentials simply will not work.

Source: Capital.com Public API documentation checked 18 Sep 2026

10 requests a second per user; one request per 0.1 seconds when opening positions or creating orders; POST /session is capped at one request a second per API key; on demo, POST /positions and /workingorders are capped at 1,000 requests an hour. Exceeding any of them returns HTTP 429.

Source: Capital.com Public API documentation checked 18 Sep 2026

The newest entry on Capital.com's changelog is 28 Nov 2023, adding demo balance top-up at POST /accounts/topUp. Code written against these docs is unlikely to be overtaken quickly.

Source: Capital.com Public API changelog checked 19 Sep 2026

The code

Illustrative and untested by us. It reads only: it opens no position.

# No official SDK. This is the whole of the login, with requests.
# DEMO ONLY. Set the three values as environment variables, never in the file.
import os
import requests

BASE = "https://demo-api-capital.backend-capital.com"  # demo host, not live

r = requests.post(
    BASE + "/api/v1/session",
    headers={"X-CAP-API-KEY": os.environ["CAPITAL_API_KEY"]},
    json={
        "identifier": os.environ["CAPITAL_IDENTIFIER"],
        "password": os.environ["CAPITAL_PASSWORD"],  # the custom API password
    },
    timeout=20,
)
r.raise_for_status()

# Both tokens come back in the response headers, not the body.
auth = {"CST": r.headers["CST"], "X-SECURITY-TOKEN": r.headers["X-SECURITY-TOKEN"]}
print(requests.get(BASE + "/api/v1/accounts", headers=auth, timeout=20).json())

The setup mistakes that cost a day

Source: Capital.com help: how to set up the MCP server checked 19 Sep 2026 We could not confirm it on any page we opened on this reading, so check it yourself before you rely on it.

Where to go next

Sections