Skip to content

We want to clarify that IG International does not have an official Line account at this time. We have not established any official presence on Line messaging platform. Therefore, any accounts claiming to represent IG International on Line are unauthorized and should be considered as fake.
CFDs are complex instruments. 70% of retail client accounts lose money when trading CFDs, with this investment provider. You can lose your money rapidly due to leverage. Please ensure you understand how this product works and whether you can afford to take the high risk of losing money.
CFDs are complex instruments. 70% of retail client accounts lose money when trading CFDs, with this investment provider. You can lose your money rapidly due to leverage. Please ensure you understand how this product works and whether you can afford to take the high risk of losing money.

Trading with APIs
Trading with APIs

How to use our APIs

Learn how to start building your API setup with us – including what REST and streaming APIs are and how to use them.

Start trading today. Call +44 (20) 7633 5430, or email to talk about opening a trading account. We’re here 24/5.

Contact us: +44 (20) 7633 5430

Start trading today. Call +44 (20) 7633 5430, or email to talk about opening a trading account. We’re here 24/5.

Contact us: +44 (20) 7633 5430

What APIs can I use with IG?

  • Web API

The Web API offering comprises our REST API and streaming API, and is available via our labs site.

It’s important to note that this API does not have its own platform. It's a solutions that provides direct access to our ecosystem, which enables you to retrieve historic data, real-time pricing and execute orders.

Effective use of the API does require previous development or coding experience. However, we do have an execution support team ready to help you with all your execution needs.

If you want to use an alternative platform that is capable of trading with algorithms instead – as well as a range of other features – you can use the ProRealTime platform.

REST API guide

What is a REST API?

REST stands for ‘representational state transfer’, which is the standard way of accessing resources on the internet. The process involves two parties; the client and the resource. In this case, the person using the API (you) is the client, and the resource is our trading ecosystem.

A REST API requires an automated request that’s written in code to trigger an automatic, static response from our system. The REST API only retrieves a screenshot of information at that point in time, so it’s used to gather specific information and take a variety of actions, like accessing account history and opening or closing positions.

How to get started with the REST API

To begin using our API:

  • Create a live account
  • Follow the My IG > Settings > API path
  • Generate your API key and security token
  • Practise building REST code using our sample apps
  • Start coding on any programme that supports HTTP

Learn more about getting started

You can also use your IG demo account to practise using our APIs, with the unique username you created when setting up your API.

How to use our REST API

Using our REST API requires an understanding of development and coding. There are four classifications of operations you should understand. These are:

  • GET, which helps you to retrieve a resource
  • POST, which lets you create a resource
  • PUT, which assists you in replacing a resource
  • DELETE, which enables you to delete a resource

With these four operation types, you can automatically set the parameters of your commands and interact with our trading system. There are a variety of different actions that fall into these four categories and cover everything from accessing your account’s history to creating an OTC (over-the-counter) order.

For a more in-depth look at how REST API components work, visit our Labs REST API guide. You can even try out our REST API by using our API companion – it gives you the complete experience so you can build your confidence making requests and viewing responses.

Examples of REST API requests

Let’s say that you wanted a list of all account history within a given date range. This would be classified as a ‘GET’ command, as you’ll be retrieving information. The coded command would be:{fromDate}/{toDate}

If you wanted to deal instead, you could create an (OTC) position through the ‘POST’ function. The command would be:

See more REST API example requests

Streaming API guide

What is a streaming API?

A streaming API, as the name suggests, provides a continuous flow of information to the user. Unlike the REST API, which is just a screenshot of a specific moment, the streaming API will continue to update the user after the initial request. This makes it useful for subscribing to markets and viewing the most up-to-date price information.

To use a streaming API, it’s advisable to have a base knowledge of REST APIs, as the two are used together.

How to get started with IG’s streaming API

To begin using our API:

  • Download the Lightstreamer client library to your programming platform
  • Create a live account
  • Generate your API key and your security token
  • Start coding on any programme that supports HTTP

Note: you’ll need a security token for logging into and accessing the API. You will then need to submit a request for an access token, with each one only valid for a limited period of time. That time period will also need to be specified by the request.

How to use our streaming API

The IG steaming API enables you to get real-time market prices, trade updates and account status notifications. To get the benefits of the live API, you’ll need to subscribe to Lightstreamer – this consists of filing a list of all the items you’d like access to (eg IG markets) and all of the fields relevant to those items (eg bid and ask prices).

For a more in-depth look at how our streaming API works, visit our Labs streaming API guide. You can even try out our streaming companion to test out the service in an interactive environment.

See the full list of streaming subscriptions

The basics of trading with APIs

Even if you’re ready to start trading APIs, it’s important to understand some of the basic concepts involved, such as what instruments you’ll be trading, how they’re priced and how to open a position.

Market instruments

Each market instrument you see on our API represents a CFD. These are derivative products, which take their price from an underlying asset. Trading CFDs enables you to go long or short on the market in question, profiting from rising and falling prices.

CFDs are leveraged, meaning you’ll put down a small deposit (called margin) to open a larger deposit. Bear in mind, though, that leveraged trading is inherently risky as your profits and losses are calculated on your full trade’s size, which can outweigh your deposit amount significantly.

Markets will have specific identifiers, which on APIs are called EPICS. Bear in mind, though, that there’s no price data available for shares on API.

For example: IX.D.FTSE.CFD.IP

In this instance, the EPIC means you’re looking to trade a CFD contract on the US Tech 100 market.

API pricing

There are two ways that you can access the most up-to-date pricing from us:

  • Subscribe to the instrument via the streaming API
  • Obtain a snapshot of the instrument’s price via the REST API. Just be aware that you are limited to around 40 trade requests per minute

Historical prices can also be requested using the REST API. As with snapshots, remember that you have a finite weekly limit of datapoints

Opening and closing a position via an API

Just like opening a position on a regular market, when you open a position through an API, you’ll need to make some basic choices.

  • Firstly, you’ll need to decide which market to trade – this should always be based on your personal preferences and interests
  • Second, you’ll need to decide at which price level to open your trade. Most traders will use fundamental and technical analysis to create a methodology for opening a position
  • Finally, you’d need to decide whether you’re buying or selling the market

Once you have reached a certain level of profit or loss, you might decide it’s time to close your position.

Both the opening and closing of positions occurs via the /positions command of the API, or the /workingorders command. Working orders will only open and close the position when a certain price level is met, similar to a regular stop or limit.

Learn more about API order types


Can I use Python with APIs?

Yes, you can use the Python programming language with us, but it’s important that you have an understanding of the package and how to test it.

In fact, you can use any programming language that supports HTTP.

Get started by trying out our API companion and streaming companion.

What historical data is available?

We provide up to 20 years of historical price data, which will be available to you depending on different resolutions – the time it takes for an entity to gather the data. For example, it could only take one second to retrieve four days’ worth of data, but it could take a full day to gather 15 years’ worth of data.

Some of our markets hold more historical data than others for each timeframe. You’ll be able to see the full scope of each market’s data by logging into our web platform – everything you see here is what you’ll be able to access through the API.

What are the risks associated with using your API?

Our API uses market instruments representing a CFD trade that happens to be automated, determined by an underlying asset or market.

CFDs are leveraged products, meaning you’ll put down a small deposit (called margin) to get exposure to a larger position. However, both profits and losses are calculated based on the position’s full size and not the margin amount. This means you run the risk of your losses or profits substantially outweighing your initial deposit.

You can use our APIs to automate your trades (although they can be done manually too), with our lightning-fast execution. In fact, orders are filled in 0.0107 seconds.1 However, this means that there is significant margin for error for those who don’t trade carefully, with multiple automated trades executed almost instantly meaning that any error you make can be exponentially magnified. So, always ensure you trade wisely and carefully.

Why has my order been rejected?

Your order might be rejected for a number of reasons, such as the market you’re attempting to trade is closed, we have had to disable API traders or there is an error with your submission.

You can use the contact us form to raise any issues.

Why can't I apply for an API key from my demo account?

If you’re having trouble setting up an API account through your demo, that’s because API accounts cannot be created from a standalone demo account, unless that demo is linked to a live account.

To create an API account, fill in our quick application form to create a live account.

1 Average speed calculated from 1 to 28 February 2022.