Dear all,
I'm having trouble deleting a position using the API. As I understand https://labs.ig.com/rest-trading-api-reference/service-detail?id=678, I'm supposed to send a DELETE request with a body. But isn't a DELETE-request supposed to be without a body?
The line
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(uri))
.headers("Content-Type", "application/json; charset=UTF-8", "Accept", "application/json; charset=UTF-8",
"Version", "2", "IG-ACCOUNT-ID", CAI,
"X-IG-API-KEY", APIKEY, "CST", CST)
.method("DELETE", HttpRequest.BodyPublishers.ofString(body))
.build();
returns a 404 not found error, but if I change DELETE to POST as in
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(uri))
.headers("Content-Type", "application/json; charset=UTF-8", "Accept", "application/json; charset=UTF-8",
"Version", "2", "IG-ACCOUNT-ID", CAI,
"X-IG-API-KEY", APIKEY, "CST", CST)
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
I get an expected error {"errorCode":"invalid.request.format.line-1.column-3"}. Does this mean that I'm supposed to use the POST method anyway? How does it then know that I',m deleting the position and not creating a new one?
I could of course delete a long position by creating a short position and vice versa, but that looks a bit messier.
Thanks for any help or clarifications.