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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 45f3d45e5d99da5d8a2bee6ef172dc04725ae63324d84713121ddc3ab4e61855
MD5 8e876bb121573d679dc0ebecfac48e43
BLAKE2b-256 34288092c36ca9640b20a96b8de6ea2d06c37c23d78625583575c664b2d30c6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ig_trading_lib-4.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb7f2ea9fcd73c66e446329c68867375fe926d8e7229e96157a5c91c07b265bb
MD5 b4db51c15f594c816c4c16a4d7f90774
BLAKE2b-256 194acc6e1e7d735b7c044bf5ae2f1540bcce4b86b07d6e5e4a55a2ef72cbc4ca

See more details on using hashes here.

Release history Release notifications | RSS feed

4.0.3

2 files

This release

4.0.2 This release

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