Skip to main content

IG Trading Library

Typed operations and safe workflows for IG's REST and streaming APIs.

The library removes protocol decisions from trading code. You call IG concepts such as markets.search, positions.create, and confirmations.get; the library owns authentication, endpoint paths, IG protocol versions, response normalisation, safe-read retries, mutation ambiguity, and streaming recovery.

Direct HTTP This library
Choose a path and protocol version Call one named operation
Build and validate dictionaries Use typed request and response models
Reimplement auth, retry, and redaction Share one hardened transport
Risk retrying an uncertain trade Receive AmbiguousExecutionError
Compose trade confirmation manually Use a safe workflow

One mental model

IG(config)
├── operations   one faithful typed IG call
└── workflows    a journey composed only from operations
  • Use ig.operations when the IG reference names the call you need.
  • Use ig.workflows when you need a complete journey such as open and confirm.
  • Use AsyncIG with await in applications built on asyncio.
  • Treat library v4 as the Python package version; IG protocol versions stay private.

Install

pip install ig-trading-lib==4.0.1

Python 3.11–3.13 is supported.

Discover and inspect

from ig_trading_lib import Environment, IG, IGConfig, SessionCredentials

config = IGConfig(
    environment=Environment.DEMO,
    credentials=SessionCredentials(
        api_key="your-api-key",
        identifier="your-identifier",
        password="your-password",
    ),
)

with IG(config) as ig:
    matches = ig.operations.markets.search("EUR/USD")
    market = ig.operations.markets.get(matches.markets[0].epic)
    print(market.instrument.epic, market.snapshot.market_status if market.snapshot else None)

Provider-added response fields remain available while documented fields are typed and normalised to snake_case.

Trade and confirm

from ig_trading_lib import CreatePositionRequest, IG, TradingPermit

request = CreatePositionRequest(
    epic="CS.D.EURUSD.CFD.IP",
    direction="BUY",
    size=1,
    order_type="MARKET",
    currency_code="GBP",
)

with IG(config, trading_permit=TradingPermit()) as ig:
    confirmation = ig.workflows.positions.open_and_confirm(request)
    print(confirmation.deal_status, confirmation.deal_id)

TradingPermit is mandatory for live mutations. Network failures after a mutation may raise AmbiguousExecutionError; reconcile the deal before deciding whether to issue another request. If confirmation retrieval fails after IG returns a deal reference, DealConfirmationError preserves that reference so you can retrieve the existing confirmation without replaying the trade.

Async

from ig_trading_lib import AsyncIG

async with AsyncIG(config) as ig:
    matches = await ig.operations.markets.search("EUR/USD")

Documentation

The automated suite uses mocked IG responses. It never submits a real demo or live trade.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ig_trading_lib-4.0.1.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ig_trading_lib-4.0.1-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file ig_trading_lib-4.0.1.tar.gz.

File metadata

  • Download URL: ig_trading_lib-4.0.1.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ig_trading_lib-4.0.1.tar.gz
Algorithm Hash digest
SHA256 67e8b53a6b15eac12b486fb2eeb3a7feff509a4f1589a9a9707e019be9ae4bb1
MD5 6bf723325860c624d7c3973ac634a28f
BLAKE2b-256 a46583c571e7b5aede30eadcb2474e5141a247d9f476730b7010c6ec875d64b9

See more details on using hashes here.

File details

Details for the file ig_trading_lib-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: ig_trading_lib-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ig_trading_lib-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3174e82f6600df183ed7719e9b69d51e3a7e4a189306a12fdbef6789536fe72
MD5 dca2a0ab5e4ee88bfead7d38cee76cc7
BLAKE2b-256 09d33bd4f74daf727ec82d55ecde10b571b9440d630524dc22c366b94219e726

See more details on using hashes here.

Release history Release notifications | RSS feed

4.0.3

2 files

4.0.2

2 files

This release

4.0.1 This release

2 files

4.0.0

2 files

3.0.1

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page