Skip to content

Conversation

@fabiankliem
Copy link

@fabiankliem fabiankliem commented Feb 4, 2026

Description

This PR adds complete IG Markets brokerage integration to the Lean engine core. The changes include:

  1. IGFeeModel.cs - New fee model implementing IG Markets pricing structure:

    • Forex/Crypto: Zero commission (spread-based pricing)
    • Index/CFD/Equity: 0.1% commission with £10 GBP minimum
  2. IGBrokerageModel.cs - Updated to return IGFeeModel instead of ConstantFeeModel(0m)

  3. BrokerageName.cs - Added IG enum value to enable transaction and execution rules for IG Markets

Related Issue

Closes #5285 - Add IG Markets brokerage support

Complete brokerage implementation available at: https://github.com/fabiankliem/Lean.Brokerages.IG

Motivation and Context

IG Markets is a leading global CFD and spread betting provider with access to forex, indices, commodities, cryptocurrencies, and equities. This integration enables Lean users to:

  • Trade with IG Markets using their existing Lean algorithms
  • Access IG's global markets (Forex, Index, CFD, Crypto, Equity)
  • Benefit from accurate fee calculation matching IG's pricing structure
  • Use both demo and live trading environments

The fee model correctly implements IG's pricing:

  • Spread-based instruments (Forex, Crypto): No explicit commission - costs built into spread
  • Commission-based instruments (Index, CFD, Equity): 0.1% commission with £10 GBP minimum

This follows the same pattern as existing brokerages (FXCM, OANDA, TradeStation, etc.) and integrates seamlessly with Lean's brokerage framework.

Requires Documentation Change

No documentation changes required. IG configuration is already present in Launcher/config.json:

  • Configuration parameters: lines 126-132
  • live-ig environment: lines 470-483

How Has This Been Tested?

Testing Environment:

  • macOS Darwin 24.6.0
  • .NET 6.0
  • Lean v2.5+

Tests Performed:

  1. Fee Calculation Tests (20+ unit tests in brokerage plugin):

    • Forex orders return zero commission ✓
    • Crypto orders return zero commission ✓
    • Index orders apply 0.1% commission with £10 minimum ✓
    • CFD orders apply 0.1% commission with £10 minimum ✓
    • Equity orders apply 0.1% commission with £10 minimum ✓
    • Minimum fee threshold validation ✓
    • Short orders calculate same fees as long orders ✓
    • Partial fills calculate proportional fees ✓
  2. Brokerage Model Tests (8+ integration tests):

    • Factory creates brokerage with correct model ✓
    • Model validates supported security types ✓
    • Model validates supported order types ✓
    • Model returns correct fee model ✓
    • GetFeeModel returns IGFeeModel instance ✓
  3. Integration Tests:

    • IGBrokerageFactory.GetBrokerageModel() returns IGBrokerageModel ✓
    • IGBrokerageModel.GetFeeModel() returns IGFeeModel ✓
    • BrokerageName.IG enum value accessible ✓

All tests pass successfully. Test files available in: Lean.Brokerages.IG/QuantConnect.IGBrokerage.Tests/

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes. (Tests located in brokerage plugin repository)
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description> *

Additional Context:

Files Changed:

  • Common/Orders/Fees/IGFeeModel.cs (new file, 117 lines)
  • Common/Brokerages/IGBrokerageModel.cs (updated GetFeeModel method)
  • Common/Brokerages/BrokerageName.cs (added IG enum value)

Complete Implementation:
The full brokerage implementation includes:

  • REST API client with authentication
  • Lightstreamer WebSocket streaming
  • Real-time market data and order updates
  • Historical data provider
  • Symbol mapper (LEAN ↔ IG EPIC codes)
  • Comprehensive test suite (30+ tests)

Repository: https://github.com/fabiankliem/Lean.Brokerages.IG


- Add IGBrokerageModel with support for Forex, CFD, Crypto, Index, Equity
- Add IG market constant to Market.cs
- Add IG configuration entries to Launcher/config.json
- Configure zero fee model (fees built into spread)
- Support Market, Limit, StopMarket, StopLimit order types
Update all project files to target .NET 6.0 instead of net10.0.
This change addresses SDK compatibility while the codebase uses C# 12 features.

Note: Building requires .NET 8+ SDK due to C# 12 syntax in Compression.cs.
The net6.0 target is for runtime compatibility.
- Add IGFeeModel implementing IG Markets fee structure
  * Forex/Crypto: Zero commission (spread-based)
  * Index/CFD/Equity: 0.1% commission with £10 GBP minimum
- Update IGBrokerageModel to use IGFeeModel instead of ConstantFeeModel
- Add IG to BrokerageName enum for transaction and execution rules

This completes the Lean engine integration for the IG Markets brokerage.
@jaredbroad
Copy link
Member

Hi @fabiankliem! Thanks for the contribution.

Please revert the .net6 changes in LEAN and upgrade the brokerage to support .net10.

Please test locally completely -- doing live trading -- before making a PR here. You can run the nunit regression tests to confirm a lot of it works (doubt these have been run at all).

Once nunit passes have LEAN compose the IG DLL as a brokerage and run a local test. Post a screen shot of the LEAN instance running and logging market data sourced the IG brokerage, and placing trades.

Will leave open for a week but will close soon as will take a fair bit of work to get ready for production. I'm not sure if prepared to take on this 😅 Claude's good but not quite up to implementing brokerages yet.

@fabiankliem
Copy link
Author

Hi @jaredbroad, thanks for taking a look. Will take care of it and do another PR once done.

Revert all 23 .csproj files from net6.0 back to net10.0, undoing the
temporary framework downgrade (e78a022). The IG brokerage plugin and
all LEAN projects now target .NET 10.

IG Markets integration changes:
- Register IG market (ID 43) in Market.cs with HardcodedMarkets entry
- Add BrokerageName.IG enum value and IGBrokerageModel to IBrokerageModel
- Add IG market hours and symbol properties to data databases
- Add live-ig environment and IG configuration keys to Launcher config.json
- Add IGLiveTestAlgorithm for live trading validation

Verified: LEAN builds with 0 errors on .NET 10, IG brokerage composes
via MEF, live test confirms Lightstreamer streaming, market data, and
trade execution all working.
@fabiankliem
Copy link
Author

@jaredbroad all nunit tests passing. See screenshot attached of LEAN instance running, getting data and placing trades.
Screenshot 2026-02-06 at 15 44 03

@jaredbroad
Copy link
Member

Epic we'll review shortly and let you know further feedback.

@jaredbroad
Copy link
Member

Hi @fabiankliem - can you please get in touch to assist with testing this? We'd love to merge your work. I sent you a connection request on LinkedIn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IG API Brokerage Integration

2 participants