IG — Best Python API for Most Traders

Fees & Spreads
4.2
Platform & Tools
4.5
Customer Service
3.8
Ease of Use
4.1
Mobile App
4.2

IG’s REST API is the best-documented broker API I’ve worked with. The Swagger/OpenAPI documentation covers every endpoint with examples, and the community-maintained trading_ig Python library wraps the raw API calls into clean, Pythonic methods. Lightstreamer provides real-time price streaming without constant polling — essential for any strategy that needs live price data.

IG demo account deposit funds page for API testing with spread betting
IG demo account for API development

Pros

  • Best API documentation of any UK broker
  • Lightstreamer for real-time price streaming
  • Community trading_ig library simplifies development
  • Spread betting via API (tax-free automated trading)
  • 17,000+ instruments accessible via API
  • FCA regulated (FRN 195355), £0 minimum deposit

Cons

  • Trading rate limit of 15 requests/minute limits high-frequency strategies
  • Lightstreamer setup is more complex than simple REST polling

What Does IG API Access Cost?

API access is free with any IG account. No additional fees, no premium tier required. Your trading costs are the same as manual trading: spread-only for spread bets (EUR/USD from 0.6 pips), commission-based for share CFDs. There are no per-API-call charges.

What’s Development Like?

IG major FX pairs list showing platform navigation and data points
IG platform data accessible via Python API

I had a working script that authenticated, pulled live GBP/USD prices, and placed a demo order within 45 minutes. The trading_ig library handles session management, token refresh, and Lightstreamer connection. The demo account mirrors the live API exactly, so you can test extensively before risking capital. See our full IG review for broader platform details.

Who Should Use IG’s API?

Python developers who want to automate spread betting or CFD trading with a well-documented, community-supported API. The 15-request/minute trading limit rules out true high-frequency strategies, but it’s ample for strategies that check prices every few seconds and trade a handful of times per day.

Spread bets and CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 70% of retail investor accounts lose money when trading spread bets and CFDs with this provider. You should consider whether you understand how spread bets and CFDs work, and whether you can afford to take the high risk of losing your money.

Capital.com — Simplest API for Python Beginners

Fees & Spreads
4.4
Platform & Tools
4.4
Customer Service
4.5
Ease of Use
4.8
Mobile App
4.9

Capital.com’s REST API is the simplest to get started with. Authentication uses an API key and password — no OAuth flow, no token management. The trade-off is no real-time streaming: you must poll for price updates, which introduces latency and counts against your rate limit. For strategies that check prices every 5–10 seconds rather than tick-by-tick, this is adequate.

Capital.com forex watchlist with AUD/USD chart in dark mode
Capital.com platform with API-accessible data

Pros

  • Simplest authentication of any broker API
  • Clean JSON responses, easy to parse
  • Spread betting available via API
  • £20 minimum deposit
  • FCA regulated (FRN 793714)

Cons

  • No real-time streaming — polling only
  • No official Python library
  • No MT5 support
  • Documentation is less detailed than IG’s

What Does Capital.com API Access Cost?

Free with any account. All trading costs are built into the spread (EUR/USD from 0.6 pips). No commission, no API fees. The £20 minimum deposit is the lowest barrier to entry for API trading among UK brokers.

What’s Development Like?

I had a working authentication and price-pull script in 20 minutes using only the requests library. No third-party wrapper needed. The simplicity is the selling point. For a first API project, Capital.com’s API removes friction and lets you focus on learning REST concepts rather than fighting authentication flows.

Who Should Use Capital.com’s API?

Python beginners building their first trading bot. The API is straightforward enough to learn REST concepts without getting bogged down in OAuth tokens or streaming protocols. Once you outgrow it, graduate to IG’s API for streaming data and a larger market range.

Spread bets and CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 65% of retail investor accounts lose money when trading spread bets and CFDs with this provider. You should consider whether you understand how spread bets and CFDs work and whether you can afford to take the high risk of losing your money.

StoneX Trading — MT4, TradingView and WebTrader for Automation

Fees & Spreads
4
Platform & Tools
3.3
Customer Service
3.3
Ease of Use
3.5
Mobile App
3.7

StoneX Trading, formerly City Index, doesn’t advertise a REST or Python API for retail clients. The automation routes it documents are MT4, for Expert Advisors written in MQL4, and TradingView, for charting and Pine Script alerts you can trade straight from inside WebTrader. If your Python workflow needs an EA as the execution layer, MT4 covers that; a documented broker-side REST endpoint simply isn’t part of what StoneX publishes.

StoneX WebTrader dashboard with a market watchlist and live price chart
Automated strategies on StoneX Trading run through MT4 Expert Advisors, while WebTrader handles manual trading.

Pros

  • MT4 gives you a familiar Expert Advisor environment to build from
  • TradingView charts and Pine Script alerts sit alongside MT4
  • Spread betting available (tax-free for most UK residents)
  • 85 FX pairs, 40+ indices, fixed 1-point UK 100 spread in market hours
  • FCA regulated (FRN 446717)

Cons

  • No published REST or Python API
  • Automation runs through MT4/TradingView rather than a broker-hosted endpoint
  • More setup than logging in to a documented REST API

What Does StoneX Python Access Cost?

There is no separate charge for building an MT4 bridge; you pay the same spreads as any other MT4 client, from 0.5 points on FX and a fixed 1 point on the UK 100 between 8am and 4.30pm. There is a GBP 12 monthly inactivity fee after 12 months dormant, which is worth knowing if a bot sits idle between builds.

What’s Development Like?

Expect an afternoon rather than 30 minutes. You write an EA in MQL4 that handles the execution side, with Python typically brought in for analysis or signal generation around it rather than talking to a broker API directly. It’s the standard MT4 pattern used across brokers generally, not something specific to StoneX, so support for the Python side comes from the wider MT4 community rather than StoneX itself.

Who Should Use StoneX for Python Trading?

Traders who already like MT4 and are comfortable building an EA-led setup, or who want Python for analysis (via WebTrader’s Performance Analytics and their own trade history exports) rather than live execution. If a clean, documented REST API is the priority, IG or Capital.com are the better starting point.

CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 68% of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you understand how CFDs work, and whether you can afford to take the high risk of losing your money.

Interactive Brokers — Most Powerful API (Steepest Learning Curve)

Fees & Spreads
3.6
Platform & Tools
3.8
Customer Service
2.4
Ease of Use
1.6
Mobile App
1.7

IBKR offers two API paths: the TWS API (socket-based, requires TWS running locally) and the newer Client Portal REST API (web-based, lighter). The TWS API via the ib_insync Python library is the most capable broker API available — you can do things no other retail API supports, like algorithmic order types, real-time portfolio Greeks, and multi-leg options orders. The cost is genuine complexity.

IBKR choose account type page for API trading setup
IBKR account setup for API access

Pros

  • Most powerful retail broker API available
  • ib_insync library is excellent and well-maintained
  • Real-time streaming via TWS socket
  • DMA with Smart Order Routing
  • Access to 150+ exchanges globally
  • FCA regulated (FRN 208159)

Cons

  • TWS must be running locally (or IB Gateway)
  • Complex setup — took me 2+ hours for first working script
  • No spread betting
  • Market data subscriptions cost extra

What Does IBKR API Access Cost?

API access is free. Trading commissions start from 0.05% with a £1 minimum on UK shares. You pay separately for market data subscriptions. The Client Portal API is free but limited in functionality compared to the TWS API. For serious development, you’ll use the TWS API, which requires TWS or IB Gateway running continuously.

What’s Development Like?

It took me over two hours to get my first working script — significantly longer than any other broker. The ib_insync library transforms the callback-heavy TWS API into async/await Python, which helps enormously. Once set up, the capabilities are unmatched: live streaming, historical data, complex order types, portfolio management, and options analytics all from Python.

Who Should Use IBKR’s API?

Experienced developers building sophisticated multi-asset trading systems. If your strategy involves options, futures, or cross-exchange arbitrage, IBKR is the only realistic choice. For straightforward forex or index CFD automation, IG is faster to implement and offers spread betting tax advantages.

62.5% of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you can afford to take the high risk of losing your money.

Which API Should a Python Beginner Start With?

Capital.com if you want the absolute simplest start. IG if you want something you won’t outgrow in six months.

Capital.com’s API requires only the requests library and basic HTTP knowledge. You can authenticate and pull prices in 10 lines of code. It’s ideal for learning REST concepts and building confidence before tackling streaming data or complex authentication.

IG’s API is a better long-term investment. The trading_ig library handles authentication and streaming for you, the documentation is thorough, and you have access to 17,000+ markets. The learning curve is steeper than Capital.com but shallower than IBKR. Most Python trading developers I know started with IG and never needed to switch.

For broader context on automated trading approaches, see our guides on building a trading bot and AI trading robots. For MT4-specific automation, read our Expert Advisors guide.

Broker API architecture diagram showing how Python connects to trading platforms via REST and WebSocket
How Python connects to broker APIs: REST and WebSocket architecture
Python API onboarding time comparison showing setup complexity across IG, Capital.com, and Interactive Brokers
API onboarding time: how long it takes to go from signup to first automated trade

Working Python Code Example – IG API Authentication & Price Pull

This script authenticates with IG’s REST API, pulls the current GBP/USD price, and prints it. It runs on Python 3.8+ with only the requests library (no trading_ig required). Replace the placeholder credentials with your IG demo account details.

import requests

# IG Demo API credentials (replace with your own)
API_KEY = "your-api-key-here"
USERNAME = "your-username"
PASSWORD = "your-password"

# Authentication
session = requests.Session()
session.headers.update({
    "X-IG-API-KEY": API_KEY,
    "Content-Type": "application/json; charset=UTF-8",
    "Accept": "application/json; charset=UTF-8",
    "Version": "2"
})

auth_payload = {
    "identifier": USERNAME,
    "password": PASSWORD
}

auth_url = "https://demo-api.ig.com/gateway/deal/session"
auth_response = session.post(auth_url, json=auth_payload)

if auth_response.status_code != 200:
    print(f"Auth failed: {auth_response.status_code}")
    exit()

# Extract tokens from response headers
cst = auth_response.headers.get("CST")
x_security_token = auth_response.headers.get("X-SECURITY-TOKEN")

session.headers.update({
    "CST": cst,
    "X-SECURITY-TOKEN": x_security_token
})

print("Authenticated successfully.")

# Pull GBP/USD price
market_url = "https://demo-api.ig.com/gateway/deal/markets/CS.D.GBPUSD.TODAY.IP"
market_response = session.get(market_url)
market_data = market_response.json()

bid = market_data["snapshot"]["bid"]
offer = market_data["snapshot"]["offer"]
spread = round(offer - bid, 4)

print(f"GBP/USD - Bid: {bid}, Offer: {offer}, Spread: {spread}")

# Clean up session
session.delete(auth_url)
print("Session closed.")

This is a starting point, not a production system. For live trading, you would add error handling, rate-limit management, and the Lightstreamer connection for real-time price streaming. The trading_ig library handles all of this automatically if you prefer a higher-level interface.

Discuss Brokers with Python APIs

Built a trading bot against one of these broker APIs? Share which Python library and broker combination worked best for you — and any authentication or rate-limit gotchas worth knowing. Our community earns Equity for helpful contributions.

Discussion 0 comments

Sort by:

No comments yet. Be the first to start discussing this topic!

Frequently Asked Questions

Is IG’s API free to use?

Yes. API access is included with any IG account at no extra cost. There are no per-request charges. Your trading costs (spreads and commissions) are the same as manual trading.

Can I automate spread betting with Python?

Yes, through IG or Capital.com. Both offer spread betting via their APIs. Spread betting profits are tax-free for most UK residents, making these the most tax-efficient options for automated trading. StoneX Trading offers spread betting too, automated through an MT4 Expert Advisor rather than a published API; Interactive Brokers does not offer spread betting at all.

Do I need a VPS to run a Python trading bot?

For strategies that need to run 24/5, yes. A cloud VPS (AWS, DigitalOcean, or similar) from roughly £5/month gives your bot reliable uptime without keeping your home computer running. For strategies that only trade during specific hours, your local machine may be sufficient.

Which Python libraries do I need?

At minimum: requests for REST API calls and pandas for data handling. For IG specifically, trading_ig simplifies authentication and streaming. For IBKR, ib_insync is essential. For backtesting, backtrader or vectorbt are popular choices.

What are the rate limits for broker APIs?

IG allows roughly 60 non-trading requests per minute and 15 trading requests per minute. Capital.com allows about 10 requests per second. IBKR’s TWS API allows 50 messages per second. These limits rule out true high-frequency trading but are ample for strategies that trade a few times per hour.

Can I use the IG API with a demo account?

Yes. IG provides a full demo API environment at demo-api.ig.com that mirrors the live API. You can develop and test your entire system on demo before switching to the live endpoint. Capital.com and Interactive Brokers offer their own demo API access too; StoneX Trading's demo account works the same way for building and testing an MT4 Expert Advisor.

References

  1. IG REST API Documentation – labs.ig.com/rest-trading-api-reference
  2. Capital.com API Documentation – open-api.capital.com
  3. Interactive Brokers API Guide – interactivebrokers.github.io/tws-api
  4. FCA Financial Services Register – register.fca.org.uk
  5. trading_ig Python Library – github.com/ig-python/trading-ig