Error "invalid.input" when deleting orders and closing positions

46 posts / 0 new
Last post
Chris
Error "invalid.input" when deleting orders and closing positions

We’re currently experiencing an issue with one of our network components, causing all DELETE requests to be delivered to our backend servers missing their body content.

So when deleting a working order or closing a position, you might encounter the error: "errorCode": "invalid.input"

To circumvent this problem please do the following:

1. change your DELETE method to POST
2. Add an header with key "_method" and value "DELETE"

This will produce the same intended result for any service expected to use the DELETE http method.

When this problem is resolved, I’ll update this post.

Chris

APItrader
Has this been resolved by now

Has this been resolved by now?

Chris
invalid.input

Hi APItrader

This is still an issue. We're working on a fix but it's more involved than first suspected. I'll update this thread when we have any updates.

Chris

ajochems
Hi,

Hi,
I am encountering this same error using the Java SDK, any progress on solving this issue? Any pointers on how to apply the workarround to the Java SDK? I am getting autowire errors when i try to extend the sdk API class to create a custom close position method.

Kind Regards,
Andre

mrpa665
HI APItrader,

HI APItrader,

Unless I made a mistake it seems not working with H "_method: DELETE"

I want to close a bull position of 1 contract:

command:
curl -v --connect-timeout 15 --max-time 15 --retry 3 --retry-delay 10 -o output -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json; charset=UTF-8" -H "X-IG-API-KEY: ***********************" -H "version: 1" -H "X-SECURITY-TOKEN: 241ec9bb0a1ec71a820e9190d8981c4483e48ab8e08b2f505cd4660e93dd5d3801112" -H "CST: 33f352490ab177c44608dc49e6a9b18dfcb7030f3c3ab3f73e7e965a3bd39d901111" -H "_method: DELETE" -X POST https://demo-api.ig.com/gateway/deal/positions/otc -d '{ "dealId": "DIAAAAALFGCSZAR", "epic": "IX.D.CAC.IFM.IP", "expiry": null, "direction": "BUY", "size": "1", "level": null, "orderType": "MARKET", "quoteId": null }'

answer:{"errorCode":"validation.mutual-exclusive-value"}

but maybe there is something wrong with my command ...

Regards,

Olivier

APItrader
For MARKET orders the

For MARKET orders the documentation says to NOT SET level or quoteId. Perhaps setting to "null" and not setting is not the same thing? What happens if you remove "level": null and "quoteId": null from your json string?

mrpa665
I get the same answer

I get the same answer

command:
curl -v --connect-timeout 15 --max-time 15 --retry 3 --retry-delay 10 -o output -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json; charset=UTF-8" -H "X-IG-API-KEY: ******************" -H "version: 1" -H "X-SECURITY-TOKEN: 241ec9bb0a1ec71a820e9190d8981c4483e48ab8e08b2f505cd4660e93dd5d3801112" -H "CST: 633f352490ab177c44608dc49e6a9b18dfcb7030f3c3ab3f73e7e965a3bd39d901111" -H "_method: DELETE" -X POST https://demo-api.ig.com/gateway/deal/positions/otc -d '{ "dealId": "DIAAAAALFGR9FA5", "epic": "IX.D.CAC.IFM.IP", "expiry": null, "direction": "BUY", "size": "1", "orderType": "MARKET" }'

answer:
{"errorCode":"validation.mutual-exclusive-value"}

But I can create, confirm and edit that position without any problems.

APItrader
The message

The message

{"errorCode":"validation.mutual-exclusive-value"}

seems to me to indicate that you are somehow giving too much input data. The documentation also says:

[Constraint: Set only one of {dealId,epic}]

so you may want to try removing one of them from your json string.

APItrader
and, if you remove "epic" you

and, if you remove "epic" you should probably also remove "expiry"...

mrpa665
It's ok now!

It's ok now!

command:
curl -v --connect-timeout 15 --max-time 15 --retry 3 --retry-delay 10 -o output -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json; charset=UTF-8" -H "X-IG-API-KEY: *********************************" -H "version: 1" -H "X-SECURITY-TOKEN: 241ec9bb0a1ec71a820e9190d8981c4483e48ab8e08b2f505cd4660e93dd5d3801112" -H "CST: 633f352490ab177c44608dc49e6a9b18dfcb7030f3c3ab3f73e7e965a3bd39d901111" -H "_method: DELETE" -X POST https://demo-api.ig.com/gateway/deal/positions/otc -d '{ "dealId": "DIAAAAALFG2JJBC", "expiry": null, "direction": "BUY", "size": "1", "orderType": "MARKET" }'

But where can I get the full documentation? I didnt' see it on the site.
Thanks!

falex
Yes ! I've got the same pb

Yes ! I've got the same pb deleting partialy a position.

So the clue is :
adding the header _method
just send the dealID ref, Direction, size and order type and it's run has it should be.

APItrader
The documentation is on this

The documentation is on this very page, check the navigation menu top left, or click below:

http://labs.ig.com/rest-trading-api-guide
http://labs.ig.com/rest-trading-api-reference

ajochems
To make this work from Java i

To make this work from Java i created a new class that extends AbstractService for closing positions. The code is:


@Service
public class ExtendedApi extends AbstractService {

private static final Logger LOG = LoggerFactory.getLogger(ExtendedApi.class);

public com.iggroup.api.positions.otc.closeOTCPositionV1.CloseOTCPositionV1Response closePositionV1(
ConversationContext conversationContext,
com.iggroup.api.positions.otc.closeOTCPositionV1.CloseOTCPositionV1Request request
) throws Exception {
String uri = getIGApiDomainURL()+ "/positions/otc";
HttpEntity<?> requestEntity;
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
if (conversationContext != null) {
if (conversationContext.getAccountSecurityToken() != null) {
requestHeaders.set(Constants.ACCOUNT_SSO_TOKEN_NAME,
conversationContext.getAccountSecurityToken());
}
if (conversationContext.getClientSecurityToken() != null) {
requestHeaders.set(Constants.CLIENT_SSO_TOKEN_NAME,
conversationContext.getClientSecurityToken());
}
requestHeaders.set(Constants.APPLICATION_KEY, conversationContext
.getApiKey());
}
requestHeaders.set(Constants.VERSION, "1");
requestHeaders.set("_method", "DELETE");
requestEntity = new HttpEntity(request, requestHeaders);
ResponseEntity response =
restTemplate.exchange(uri, HttpMethod.POST, requestEntity, com.iggroup.api.positions.otc.closeOTCPositionV1.CloseOTCPositionV1Response.class);
return response.getBody();
}
}

Chris
To make this work from Java

Hey ajochems,

Thanks for the update. We're going to update future SDKs so that you won't have to implement these workarounds.

Cheers,
Chris

Fabian
Hi ajochems,

Hi ajochems,

i tried this workaround but i get a NullPointerException of the "restTemplate" Object in ExtendedApi. Can you help me?

Thanks,
Fabian

Fabian
Ok i have seen the new Java

Ok i have seen the new Java SDK 2.0.5.
I will try it.

sammyyallen
Can't seem to get this to work

Have same problem added headers, and change sample code from Delete to Post

======= Sample C# API Code ======================
///
///Closes one or more OTC positions
///@param closePositionRequest the request for closing one or more positions
///@return OTC close position response
///
public async Task> closePosition(ClosePositionRequest closePositionRequest)
{
return await _igRestService.RestfulService("/gateway/deal/positions/otc", HttpMethod.Post, "1", _conversationContext, closePositionRequest,

====== Request ==============
POST https://demo-api.ig.com/gateway/deal/positions/otc HTTP/1.1
X-IG-API-KEY: f62f77e153db4f19624c5e5c718f3489d8bff634
CST: 2d888ca65551d06099531f44197529ab4149ebe1a4823bc37708d35bc58c5a0901111
X-SECURITY-TOKEN: d0f7bc0c4b037785077ce5bb7701a60166e5488c62e65c591553420e67d325de01112
VERSION: 1
_method: DELETE
Content-Type: application/json
Host: demo-api.ig.com
Content-Length: 133
Expect: 100-continue

{"dealId":"DIAAAAALWE783BC","epic":null,"expiry":null,"direction":"SELL","size":"1","level":null,"orderType":"Market","quoteId":null}

==== Response ===============
HTTP/1.1 400 Bad Request
Server: Apache
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, X-IG-API-KEY, CST, X-SECURITY-TOKEN, VERSION, _method
Access-Control-Expose-Headers: CST, X-SECURITY-TOKEN
Access-Control-Max-Age: 3600
X-STATE: live
Pragma: no-cache
Cache-Control: no-cache, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Language: en-GB
P3P: CP="ALL DSP LAW OTPa OUR IND UNI CNT"
Content-Type: application/json;charset=UTF-8
Vary: X-IG-API-KEY
Date: Mon, 13 Apr 2015 06:03:04 GMT
Connection: close

{"errorCode":"invalid.input"}

APItrader
It seems like the API is

It seems like the API is sometimes case-sensitive and sometimes not. Have you tried: "orderType":"MARKET"?

BARD
Delete in c# or vb.NET

Hi
I am new here
i can make a position like this

Dim newPosition As CreatePositionRequest = New CreatePositionRequest

newPosition.direction = "BUY"

newPosition.currencyCode = "EUR"
newPosition.epic = MarketEPIC
newPosition.forceOpen = True
newPosition.guaranteedStop = False
newPosition.limitDistance = 10
newPosition.orderType = "MARKET"
newPosition.size = 1
newPosition.stopDistance = 10
newPosition.expiry = "-"

Dim r As IGPublicPcl.IgResponse(Of CreatePositionResponse) = Await igRestApiClient.createPositionV1(newPosition)
r = r
DealID = r.Response.dealReference.ToString

this works

so when i will close this position i have an internel 500 Error

Dim closePosition As ClosePositionRequest = New ClosePositionRequest
closePosition.dealId = DealID
closePosition.direction = "SELL"
closePosition.expiry = "-"
closePosition.size = 1
closePosition.orderType = "MARKET"

Dim r As IGPublicPcl.IgResponse(Of ClosePositionResponse) = Await _igRestApiClient.closePosition(closePosition)

what make i wrong?

kris
API Companion: Close Position: Invalid Input

API companion, input for closing postion gives me invalid input error. Where have I gone wrong? I was able to create the same position using API companion.
{
"dealId": "DIAAAAALXL37PA3",
"epic": "CS.D.EURUSD.CFD.IP",
"expiry": null,
"direction": "SELL",
"size": "1",
"level": null,
"orderType": "MARKET",
"quoteId": null
}

APItrader
Is that a short position (you

Is that a short position (you said that you "created the same position")? If so, you need "direction": "BUY" to close it.

kris
Closing Position error

To make thing more clear
Position created successfully:
{
"positions": [{
"position": {
"contractSize": 1.0,
"createdDate": "2015/04/21 19:53:58:000",
"dealId": "DIAAAAALXPFPYA6",
"size": 2.0,
"direction": "BUY",
"limitLevel": null,
"level": 7049.0,
"currency": "AUD",
"controlledRisk": false,
"stopLevel": null,
"trailingStep": null,
"trailingStopDistance": null
},
"market": {
"instrumentName": "FTSE 100 Cash (A$1 Contract)",
"expiry": "-",
"epic": "IX.D.FTSE.IFA.IP",
"instrumentType": "INDICES",
"lotSize": 1.0,
"high": 7075.8,
"low": 7048.5,
"percentageChange": 0.06,
"netChange": 4.3,
"bid": 7067.3,
"offer": 7072.3,
"updateTime": "00:38:16",
"delayTime": 0,
"streamingPricesAvailable": true,
"marketStatus": "TRADEABLE",
"scalingFactor": 1
}
}]
}

I tried the following to close with no success, after your suggestion
{
"dealId": "DIAAAAALXPFPYA6",
"epic": "IX.D.FTSE.IFA.IP",
"expiry": "-",
"direction": "BUY",
"size": "2",
"level": null,
"orderType": "MARKET",
"quoteId": null
}
{
"errorCode": "invalid.input"
}

{
"dealId": "DIAAAAALXPFPYA6",
"epic": "IX.D.FTSE.IFA.IP",
"expiry": "-",
"direction": "SELL",
"size": "2",
"level": null,
"orderType": "MARKET",
"quoteId": null
}
{
"errorCode": "invalid.input"
}

HELP!

APItrader
Try not setting "epic".

Try not setting "epic". (Constraint: Set only one of {dealId,epic}])

kris
Hi APItrader

Hi APItrader
Thanks for your prompt responses.

I am long 1 which has a dealid as under. I tried with Both direction as buy and sell. Still i keep getting error invalid input
{
"dealId": "DIAAAAALXXAUUAG",
"epic": null,
"expiry": null,
"direction": "BUY",
"size": "1",
"level": null,
"orderType": "MARKET",
"quoteId": null
}

I also discovered that after getting a statuscode=200 on createposition. no actual position is created very often. Any suggestion why this happens

APItrader
When closing a long position

When closing a long position "direction" should be "SELL". My last suggestion is to try not setting epic, expiry, level, and quoteId at all, i.e., leaving them out altogether rather than setting them to "null".

It would simplify things if you only needed to do
DELETE /positions/otc/{dealId}
with no parameters to close a position. I'm not sure why it's not done that way.

statuscode=200 when creating a position only means that the system received and accepted your request. To find out whether a position was created or not (and, if not, why) you need to do a GET /confirms/{dealReference} using the dealReference returned in the response from "createposition" (or subscribe to the CONFIRMS stream).

kris
Hi APItrader

Hi APItrader

To overcome the problem of closing position, I tried creating a opposite position (Sell if I am long and BUY if I am short) from API companion and it worked by nullified my position. However When I try to the same using the API codes that I am developing it come with response Error: BAD Request. The same codes is able to get response 200 (Its another matter that actual position is not created sometimes for some reason, as i mentioned in my earlier post). Other than these nagging problems My API app is coming up fine

APItrader
> (Its another matter that

> (Its another matter that actual position is not created sometimes for some reason, as i mentioned in my earlier post)

see the last part of my reply above

PascalSonia
Have you a solution for EXCEL ?

Following the reference API guide, I built a VBA macro for delete a position :

Public Function DeletePosition(DealReference As String, Quantite As String, Direction As String) As String

Call oXMLHTTP.Open("DELETE", IG_API_HOST + "/positions/otc", False)

Dim requestBodyDictionary As Dictionary
Set requestBodyDictionary = New Dictionary
Call requestBodyDictionary.Add("dealId", DealReference)
Call requestBodyDictionary.Add("direction", Direction)
Call requestBodyDictionary.Add("size", Quantite)
Call requestBodyDictionary.Add("orderType", "MARKET")

Dim requestBodyString As Variant
requestBodyString = JSON.toString(requestBodyDictionary)
Call oXMLHTTP.SetRequestHeader("X-SECURITY-TOKEN", m_accountToken)
Call oXMLHTTP.SetRequestHeader("CST", m_clientToken)
Call oXMLHTTP.SetRequestHeader("X-IG-API-KEY", m_apiKey)
Call oXMLHTTP.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
Call oXMLHTTP.SetRequestHeader("Accept", "application/json; charset=utf-8")
Call oXMLHTTP.send(requestBodyString)

Dim responseData As Dictionary
Set responseData = JSON.parse(oXMLHTTP.responseText)
If oXMLHTTP.Status = 200 Then
DeletePosition = responseData.Item("dealReference")
Else
[APIMsg] = oXMLHTTP.responseText
DeletePosition = ""
End If

End Function

----

But I have always 'errorCode:invalid.input'

I try to reverse the direction... KO
I add the expiry... KO
I replace the dealOd by the epic... KO
I kill the pig... KO
I...
I...

I have no idea

Please, can you help me ?

APItrader
Are you making a DELETE or a

Are you making a DELETE or a POST request? If DELETE, you should read the first entry in this thread.

Also, do you literally mean "DealReference" or is it just an (unfortunately chosen) name of an internal variable containing the DealId?

PascalSonia
Thanks APItrader,

Thanks APItrader,

I'm going to try the method indicates in the first entry of this post.

For the 'DealReference', it's just a bad name because it's really the DealId used. I'm going to change the name.

PascalSonia
THE solution (VBA EXCEL)

Thanks to all community, this is the solution :

EXCEL VBA Sub to delete an otc position

PascalSonia
Last update

Hi, it's not "POST" but "PUT"

"_method" is added into the header. It's not an attribut like "dealId" or "direction"

Good trade

Konsti
error

I have tried all the options listed above and i still keep getting the same error, but it's not invalid input.

Here is the post request:

POST /gateway/deal/positions/otc HTTP/1.1
Host: demo-api.ig.com
Content-Type: application/json;charset=UTF-8
Accept: application/json;charset=UTF-8
X-IG-API-KEY: *****************************
version: 1
X-SECURITY-TOKEN: 4686a6289294630da501b04b806b58002c36b2c97a941a31eb9971cc30acadca01113
CST: e16bad215d0f8395f4e54503a74761e79b9dcedfaf18888df19d320bbffecbf601113
_method: DELETE
Cache-Control: no-cache

{ "dealId": "DIAAAAAL9Y3WUA6", "direction": "SELL", "size": "0.1", "orderType": "LIMIT" }

i always get the same result : "errorCode": "validation.not-null-conditional-set-value".

However, if I add the "epic" = null and "expiry" = null i get the error.invalid-input erorr message.

Can someone help? I have also tried the ExtendedAPI.java class listed above and i get the same result...

APItrader
You need to either set "level

You need to either set "level" for a LIMIT order or use orderType MARKET.

Konsti
Thank you API Trader. I am

Thank you API Trader. I am trying to close a binary option position. So I can't use orderType MARKET. It seems that the binary options are not automatically closed after their expiry when the order has been placed through the API. When I try to close the binary position after the expiry by providing a level I get a system error code: "errorCode": "system.error". Also, when I look in the companion app I see the following under open positions while the position already expired.

{
"positions": [{
"position": {
"contractSize": 10.0,
"createdDate": "2015/06/09 14:03:48:000",
"dealId": "DIAAAAAMBKF38A4",
"size": 0.1,
"direction": "BUY",
"limitLevel": null,
"level": 75.4,
"currency": "USD",
"controlledRisk": false,
"stopLevel": null,
"trailingStep": null,
"trailingStopDistance": null
},
"market": {
"instrumentName": "EUR/USD to be above 11246.3 at 2:05pm",
"expiry": "09-JUN-15",
"epic": "VB.D.ED1300UD.01.IP",
"instrumentType": "BINARY",
"lotSize": 10.0,
"high": 100.0,
"low": 0.0,
"percentageChange": 0.0,
"netChange": 0.0,
"bid": 48.0,
"offer": 52.0,
"updateTime": "13:16:30",
"delayTime": 0,
"streamingPricesAvailable": true,
"marketStatus": "EDITS_ONLY",
"scalingFactor": 1
}
}]
}

ixta
Did you ever work out how to

Did you ever work out how to close a Binary position?

For the life of me I can't work it out. I've added the _method header and tried POST and PUT but always end up with the invalid.input response

POST /gateway/deal/positions/otc HTTP/1.1
Host: demo-api.ig.com
Accept-Encoding: gzip, deflate
Accept: application/json; charset=UTF-8
User-Agent: python-requests/2.3.0 CPython/2.7.8 Windows/2008ServerR2
X-IG-API-KEY: xyz
X-SECURITY-TOKEN: abc
CST: def
content-type: application/json; charset=UTF-8
_method: DELETE
Content-Length: 95

{"orderType": "LIMIT", "direction": "BUY", "size": 1, "level": 90, "dealID": "DIAAAAAMYFGxxxx"}

response:

{"errorCode":"invalid.input"}

Chris
Closing Binary Positions

Hi ixta,

Did you ever manage to close a Binary Position?

Chris

LTodini
Closing Position Problem c#

Hi guys, the error "invalid.input" still persist on closing position. There are any news on that? Can you inidcate if esists any workaround?

Chris
Closing Position Problem c#

Hi LTodini,

The workaround for this issue can be found at the top of this post, are you not able to use this. Also, we have updated the demo servers as well (https://labs.ig.com/node/288).

Let me know how you get on.

Chris

markleeds
Closing working orders

Can't seem to close open working orders using the web page api companion, I suspect this is related? +1 for a fix please

Raven
Cannot close a position

Hi All,

I cannot close an open BUY position. I get "errorCode":"invalid.input". This is my code:
function placeTrade_CLOSE_Deal() {
xhr.open("POST", urlRoot + "/positions/otc", false);
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xhr.setRequestHeader("Accept", "application/json; charset=UTF-8");
xhr.setRequestHeader("X-IG-API-KEY", apiKey);
xhr.setRequestHeader("X-SECURITY-TOKEN", account_token);
xhr.setRequestHeader("CST", client_token);
xhr.setRequestHeader("Version", "1");

var bodyParams = {};
bodyParams["_method"] = "DELETE";
bodyParams["dealId"] = "DIAAAAAPE2X8AAR"
bodyParams["direction"] = "SELL";
bodyParams["size"] = 1;
bodyParams["orderType"] = "MARKET";
ReqBody = JSON.stringify(bodyParams);
output(ReqBody);

var resultData;
xhr.send(ReqBody);
resultData=xhr.responseText;
output(resultData);
}

This is the message body:
{"_method":"DELETE","dealId":"DIAAAAAPE2X8AAR","direction":"SELL","size":1,"orderType":"MARKET"}

Please can I get some help with this.

Raven
Resolved

I managed to resolve this. I was adding "_method" = "DELETE" in the body of the request instead of the header.

Pavel
i'm using in the header "

i'm using in the header "_method : DELETE"
and the body of request is that but it doesn't work
why?

{
"dealId ": "DIAAAAAPMESHKBA",
"direction": "SELL", (or "BUY")
"size": 1,
"orderType": "MARKET"
}

stefek99
Original post from August 2014, is it fixed in January 2016?

API Companion: http://labs.ig.com/sample-apps/api-companion/index.html

Logout does not DELETE to /session

Logout POST to /session and has _method:DELETE in headers...

So I wonder if POST / DETELE thing has been fixed?

Chris
Original post from August 2014, is it fixed in January 2016?

Hey stefek99,

We haven't added a new endpoint yet, as there is a workaround. It is on our radar to change though, because it is a support pain point.

Chris

star_wibble
Different error code

Hi Chris,

This also fixed instances of the validation.null-not-allowed.request error, when sending DELETE requests to close a position.

I just wanted to get the error onto this thread because I spent three days trying to work out what is wrong with the Haskell client I'm developing, and the answer was pinned to the top but I missed it because it referred to a different error!

James

Log in or register to post comments