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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 bae45150a2a8b162842cfe7932835c0f49faeff9831b79bbb3dfbe429776cfc2
MD5 fd1c519823e19cf3b6c6ad96a8ae64d2
BLAKE2b-256 da461433a1eed4f54b6b593a7ce5d5b83f2dd3c7a0e2a86c59c818deeec4f01d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5146c5b6e1a811902383ac490a73641cc9ece20ba8866dce907cf54f3fbe0521
MD5 9214119ef170ebfab6c431f9a63a6ee9
BLAKE2b-256 0dd8ce71bbd722e01c7b5f64d789779c8b1f67ea0b505ea7cadd6bc60ef97c47

See more details on using hashes here.

Release history Release notifications | RSS feed

4.0.3

2 files

4.0.2

2 files

4.0.1

2 files

This release

4.0.0 This release

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