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.3

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.3.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.3-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 bb8f30a0bc3370f2eab3b2750dbc3874c2fac2d1d98e199a60264a91008ea14c
MD5 5c55a4cfcd888f51afefa6493c4d59ae
BLAKE2b-256 23815295b6db2d61103c309867589d60068dd39a61f0262a5b22aab3ec4be56e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70da7ae7c2c9a3dee417f6270877c6164fa216ccdcfc627e898fcccb01680d33
MD5 224e3b4c84a63ea449c4054b6c65369b
BLAKE2b-256 4478d1e446fb9488f10cee314bae872a7e6643b7de59b9b4157ee9c6e23f4dd8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

4.0.3 This release

2 files

4.0.2

2 files

4.0.1

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