IG Markets added a new set of endpoints to their API sometime in late 2023 or early 2024. I’m going to have a crack at adding support for those new endpoints to trading-ig.
The new endpoints are documented here, down at the bottom under Indicative costs and charges:
https://labs.ig.com/rest-trading-api-reference.html
As far as I know, there was no announcement anywhere about the changes. The IG Community pages were abruptly removed some time ago. The IG Labs page has links to a LinkedIn profile, and a Twitter account, but no activity there. So it’s hard to know what the driver is for this new functionality. And who knows what this means?
website IDs: atm, atf, dem, def, det, esm, esf, est, frm, frf, frt, itm, itf, itt, nlm, nlf, nlt, nom, nof, not, sem, sef, set, eng, enf, ent, iei, iem, ief, iet, igi, igm, por, pof.
Nevertheless, the docs are there, so let’s see what this new stuff does.
The first step is to enlist the help of my trusty code wrangler Claude - after a brief chat, he made very short work of implementing the four new methods:
https://github.com/bug-or-feature/trading-ig/commit/0ebe47f90e0d1f8bdcf08aa26b416a6fce5456e3
Top job Claude! That would have taken me hours a few years ago. I usually run the code to see what the responses look like. Then we’ll know whether we need to create unit or integration tests, or both. For these endpoints, we don’t really know what they’re even for yet, so let’s see what comes back. The history one looks like the easiest one to try, as it doesn’t need any setup. Presumably, it gives a summary of costs and charges for the given dates. Let’s see:
import logging
from trading_ig.config import config
from trading_ig.rest import IGService
ig_service = IGService(
config.username,
config.password,
config.api_key,
acc_number=config.acc_number,
acc_type=config.acc_type,
)
ig_service.create_session(version="2")
response = ig_service.fetch_indicative_costs_history(
# User-specified from date (yyyy-MM-dd'T'HH:mm:ss. SSSXXX)
"2025-01-01T00:00:00. 000+01:00",
"2025-10-31T00:00:00. 000+01:00"
)
print(f"fetch_indicative_costs_history: {response}")
Hmm, the date format is a little odd - not an ISO 8601 standard with that space after the dot. Maybe a typo? And it’s a bit strange that we need to specify the microseconds and timezone anyway. Plus, that means there are now four different datetime formats to deal with in the IG API <sigh>. Anyway, the response is an error:
Exception: {"errorMessage":"Required request parameter 'pageSize' for method parameter type int is not present"}
That implies that the pageSize parameter is missing. Even though the docs say it’s optional. Not a great start. OK, let’s add it to the rest.py function, and try again
1def fetch_indicative_costs_history(
2 self,
3 from_date,
4 to_date,
5 session=None,
6):
7
8 self.non_trading_rate_limit_pause_or_pass()
9 version = "1"
10 params = {}
11 params["pageSize"] = 20
12 url_params = {"from": from_date, "to": to_date}
13 endpoint = "/indicativecostsandcharges/history/from/{from}/to/{to}".format(
14 **url_params
15 )
16 action = "read"
17 response = self._req(action, endpoint, params, session, version)
18 data = self.parse_response(response.text)
19
20 return data
and the response
Exception: {"errorMessage":"Required request parameter 'pageNumber' for method parameter type int is not present"}
Oh dear. Why am I not surprised? OK, let’s add params["pageNumber"] = 1 too.
trading_ig.rest.IGException: Server problem: status code: 500, reason: Internal Server Error
OK, that is not good. Life is too short to deal with this sort of nonsense so late in the day. Time for a beer and Champions League footy.
To be continued at a later date…