SDKs overview

IG provides a suite of tools for developers to interact with its trading platform programmatically. These include official Software Development Kits (SDKs) and a range of community-contributed libraries. The primary goal of these SDKs is to simplify the process of accessing IG's REST API, allowing developers to build custom applications for automated trading, market data analysis, and account management. The official IG REST API reference details the available endpoints for real-time market data, order placement, and account information.

Developers utilize these SDKs to implement various trading strategies, from high-frequency trading algorithms to long-term portfolio management tools. The SDKs abstract the HTTP requests and response parsing, offering developers a more convenient, object-oriented interface in their preferred programming language. This abstraction handles authentication, error handling, and data serialization, reducing development time and potential integration issues. For example, developers can fetch historical price data, monitor open positions, or execute trades directly from their applications, without needing to interact with the web-based trading platform user interface. The official documentation emphasizes secure API key management and rate limit considerations for optimal integration performance, as outlined in the IG platform glossary.

Official SDKs by language

IG offers official SDKs designed to facilitate integration with its trading APIs. These SDKs are maintained by IG and provide a stable, supported interface for common programming languages. The official SDKs typically encompass functionalities for authentication, market data retrieval, order execution, and account management. Developers can find detailed documentation and usage examples on the IG Labs developer portal.

The following table summarizes the key official SDKs available:

Language Package Name Install Command Maturity
Python ig-markets-api-python-sdk pip install ig-markets-api-python-sdk Stable
Java ig-markets-api-java-sdk Maven/Gradle dependency Stable

Each official SDK is designed to align with the latest version of the IG REST API, ensuring compatibility and access to the newest features. The Python SDK, for instance, provides classes for managing various instrument types, placing different order types (e.g., limit, stop, market), and subscribing to streaming price updates via WebSockets. Similarly, the Java SDK offers robust object models for handling trading accounts, positions, and dealing tickets. These SDKs are typically open-source, allowing developers to inspect the code and contribute to their improvement, fostering transparency and community engagement, as is common with many financial API SDKs, such as Stripe's API libraries.

Installation

Installing IG's official SDKs depends on the programming language chosen. Below are common installation methods for the primary supported languages.

Python SDK Installation

The Python SDK can be installed using pip, the standard package installer for Python. Ensure you have Python 3.7+ installed on your system.

pip install ig-markets-api-python-sdk

After installation, you can import the necessary modules into your Python scripts:

from IGMarkets import IGMarkets
from IGMarkets.stream import IGStreamService

Java SDK Installation

For Java projects, the IG SDK is typically managed through build automation tools like Maven or Gradle. You need to add the appropriate dependency to your project's pom.xml (for Maven) or build.gradle (for Gradle) file.

Maven Dependency

Add the following to your pom.xml:

<dependency>
    <groupId>com.iggroup.api</groupId>
    <artifactId>ig-markets-api-java-sdk</artifactId>
    <version>LATEST_VERSION</version> <!-- Replace with the latest version -->
</dependency>

Gradle Dependency

Add the following to your build.gradle:

implementation 'com.iggroup.api:ig-markets-api-java-sdk:LATEST_VERSION' // Replace with the latest version

Ensure you replace LATEST_VERSION with the most current version number, which can be found in the IG Labs documentation or a public Maven repository. Once the dependency is added and your project is built, you can import the SDK classes into your Java code to begin development.

Quickstart example

This quickstart demonstrates how to use the Python SDK to log in to the IG platform, retrieve market data for a specific instrument, and log out. This example assumes you have your API key, username, and password ready.

from IGMarkets import IGMarkets
from IGMarkets.stream import IGStreamService
import logging

# Configure logging for better visibility
logging.basicConfig(level=logging.INFO)

# --- Configuration --- 
# Replace with your actual credentials and API key
USERNAME = "your_username"
PASSWORD = "your_password"
API_KEY = "your_api_key"
DEMO_ACCOUNT = True # Set to False for live account

# --- Initialize IGMarkets API --- 
ig_api = IGMarkets(USERNAME, PASSWORD, API_KEY, DEMO_ACCOUNT)

try:
    # --- Login --- 
    ig_api.create_session()
    logging.info("Successfully logged in to IG Markets.")

    # --- Fetch Market Data (Example: EUR/USD) ---
    # First, search for the instrument to get its epic (market identifier)
    search_results = ig_api.search_markets("EUR/USD")
    eur_usd_epic = None
    if search_results and search_results['markets']:
        for market in search_results['markets']:
            if market['instrumentName'] == 'EUR/USD':
                eur_usd_epic = market['epic']
                break
    
    if eur_usd_epic:
        logging.info(f"Found EUR/USD epic: {eur_usd_epic}")
        # Get detailed market information
        market_details = ig_api.get_market_details(eur_usd_epic)
        if market_details:
            logging.info(f"EUR/USD Market Details:")
            logging.info(f"  Bid: {market_details['snapshot']['bid']}")
            logging.info(f"  Offer: {market_details['snapshot']['offer']}")
            logging.info(f"  High: {market_details['snapshot']['high']}")
            logging.info(f"  Low: {market_details['snapshot']['low']}")
        else:
            logging.warning("Could not retrieve EUR/USD market details.")
    else:
        logging.error("EUR/USD market epic not found.")

    # --- Example: Fetching account details (optional) ---
    account_details = ig_api.get_accounts()
    if account_details and account_details['accounts']:
        logging.info(f"Account ID: {account_details['accounts'][0]['accountId']}")
        logging.info(f"Balance: {account_details['accounts'][0]['balance']['balance']}")
    else:
        logging.warning("Could not retrieve account details.")


except Exception as e:
    logging.error(f"An error occurred: {e}")
finally:
    # --- Logout --- 
    if ig_api.lightstreamer_client is not None:
        ig_api.lightstreamer_client.disconnect()
    ig_api.logout()
    logging.info("Logged out from IG Markets.")

This script first initializes the IGMarkets object with your credentials. It then attempts to create a session, searches for the EUR/USD market to obtain its unique identifier (epic), and retrieves detailed market information including bid, offer, high, and low prices. Finally, it logs out to terminate the session securely. Error handling is included to catch potential issues during API calls. For real-time streaming data, the IGStreamService would be used in conjunction with WebSockets, as described in the IG Labs getting started guide.

Community libraries

Beyond the official SDKs, the IG developer community has contributed various libraries and wrappers that extend functionality or offer support for additional programming languages. These community-driven projects can provide alternative approaches to integration, specialized tools for data analysis, or utilities for specific trading strategies. While not officially supported by IG, they can be valuable resources for developers seeking flexibility or solutions tailored to niche requirements.

Examples of community contributions often include:

  • Unofficial Python wrappers: These might offer different object models, simplified interfaces for specific tasks, or integration with other Python data science libraries like Pandas or NumPy for advanced analytical capabilities.
  • JavaScript/TypeScript libraries: For web-based applications, community libraries might provide client-side wrappers for interacting with IG APIs, potentially leveraging frameworks like React or Angular for dynamic user interfaces.
  • C#/.NET libraries: Developers working within the Microsoft ecosystem might find community-developed libraries that provide a .NET-native interface to the IG REST API, integrating seamlessly with applications built on Windows or Azure.
  • Specialized tools: These could range from backtesting frameworks that simulate trading strategies against historical data to visualization tools that display real-time market movements in custom chart formats.

When considering community libraries, it is important to evaluate their maintenance status, documentation quality, and community support. Developers should refer to platforms like GitHub to assess the activity and reliability of these projects. While community libraries can accelerate development, they may not always keep pace with changes in the IG API, requiring manual updates or adjustments. Users are encouraged to review the code and understand its implications before integrating into production systems. For instance, best practices for secure API key management, as outlined by general API security guidelines from organizations like the IETF in RFC 6750 for Bearer Token Usage, should always be followed, regardless of whether an official or community SDK is used.