Jump to content
  • 0

Close Position Using rest API


Guest oliver3146

Question

Guest oliver3146

Hi all,

I'm currently using IG rest API top open and positions. I don't have any issue opening a position but when I try to close it I get below error message:

"errorCode": "validation.mutual-exclusive-value.request"

I also get this error when using API companion:

Deal Id: DIAAAADQNQBZCAH
Epic: IX.D.SPTRD.IFE.IP
Expiry: -
Direction:  SELL (because my position is BUY)
Deal Size: 1
Closing order Level: 
Order Type:  MARKET
Time In Force: 
Quote ID: 

 (DELETE /positions/otc)

 

After I press GO I get error: "errorCode": "validation.mutual-exclusive-value.request" the same I get using python API.

Could you please help ? What am I doing wrong?

 

Thanks in advance

Link to comment

23 answers to this question

Recommended Posts

  • 1

If anyone is still having this problem, the answer is to use the POST method on your httpClient obj (whatever you're using) and set a header value. ("_method": "DELETE")

It needs to be POST because you're adding a request body, which isn't supposed to work with the DELETE verb.

So a request will look like this:

Method: POST

POST body:
{
    "dealId": "<deal id>",
    "direction": "SELL",
    "size": "1",
    "orderType": "MARKET",
}
All the rest could be null

Headers:
X-IG-API-KEY: <your api key>
X-SECURITY-TOKEN: <your token from logging in>
CST: <your cst token from logging in>
Content-Type: application/json
Version: 1
_method: DELETE

Hope this helps

  • Thanks 1
Link to comment
  • 0
On 05/05/2020 at 19:14, Guest oliver3146 said:

Hi all,

I'm currently using IG rest API top open and positions. I don't have any issue opening a position but when I try to close it I get below error message:

"errorCode": "validation.mutual-exclusive-value.request"

I also get this error when using API companion:

Deal Id: DIAAAADQNQBZCAH
Epic: IX.D.SPTRD.IFE.IP
Expiry: -
Direction:  SELL (because my position is BUY)
Deal Size: 1
Closing order Level: 
Order Type:  MARKET
Time In Force: 
Quote ID: 

 (DELETE /positions/otc)

 

After I press GO I get error: "errorCode": "validation.mutual-exclusive-value.request" the same I get using python API.

Could you please help ? What am I doing wrong?

 

Thanks in advance

 

Link to comment
  • 0

Deal Id: DIAAAADQNQBZCAH
Epic:
Expiry:
Direction:  SELL (because my position is BUY)
Deal Size: 1
Closing order Level:
Order Type:  MARKET
Time In Force:
Quote ID:

 (DELETE /positions/otc)

When i send this request via command: "Call oXMLHTTP.SEND(requestBodyString)"

i get this error: "errorCode": "validation.null-not-allowed.request"

if i copy request text to API companion . It runs perfectly

Any body got a solution to this?

Link to comment
  • 0

request body string :{"dealId":"DIAAAAGVJZBK3AZ","direction":"SELL","size":"1","orderType":"MARKET","timeInForce":"EXECUTE_AND_ELIMINATE"}
Method : (DELETE /positions/otc)
When i send this request via command: "Call oXMLHTTP.SEND(requestBodyString)"
i get this error: "errorCode": "validation.null-not-allowed.request"
if i copy request text to API companion . It runs perfectly

Any body got a solution to this?

Link to comment
  • 0

request body string :{"dealId":"DIAAAAGVJZBK3AZ","direction":"SELL","size":"1","orderType":"MARKET","timeInForce":"EXECUTE_AND_ELIMINATE"}
Method : (DELETE /positions/otc)
position : "BUY"
When i send this request via command: "Call oXMLHTTP.SEND(requestBodyString)"
i get this error: "errorCode": "validation.null-not-allowed.request"
if i copy request text to API companion . It runs perfectly

Any body got a solution to this?

Link to comment
  • 0
On 28/10/2021 at 18:14, Guest Simon said:

Deal Id: DIAAAADQNQBZCAH
Epic:
Expiry:
Direction:  SELL (because my position is BUY)
Deal Size: 1
Closing order Level:
Order Type:  MARKET
Time In Force:
Quote ID:

 (DELETE /positions/otc)

When i send this request via command: "Call oXMLHTTP.SEND(requestBodyString)"

i get this error: "errorCode": "validation.null-not-allowed.request"

if i copy request text to API companion . It runs perfectly

Any body got a solution to this?

I think so expiry needs a '-' as value.

 

Link to comment
  • 0

I am also running into issue when trying to delete a position when following payload 

{
   "dealId": "DIAAAAJBD8TYKAT",
   "direction": "SELL",
   "orderType": "MARKET",
   "timeInForce": "FILL_OR_KILL",
   "size": 1.16,
   "expiry": "DFB"
}

 

endpoint https://demo-api.ig.com/gateway/deal/positions/otc

when I use POST method with _method header as DELETE, it returns 

{
"errorCode": "error.service.marketdata.position.notional.details.null.error"
}
 
when I use DELETE method 
validation.null-not-allowed.request
 
Will appreciate any help in this regard. 
Link to comment
  • 0

Where you able to get this to work? When I add the _method = DELETE header, I get a 404 file not found, but I've checked the URI about 718 times. I'm able to create new positions, and also to delete using the API companion.

The following is a printout from my post() method when creating a position:

IgAPI.post: URI: https://demo-api.ig.com/gateway/deal/positions/otc
IgAPI.post: Headers: java.net.http.HttpHeaders@2c272c73 { {Accept=[application/json; charset=UTF-8], Content-Type=[application/json; charset=UTF-8], CST=[removed], IG-ACCOUNT-ID=[removed], Version=[2], X-IG-API-KEY=[removed]} }
IgAPI.post: Body: {"currencyCode":"USD","direction":"BUY","epic":"IX.D.SPTRD.IFM.IP","expiry":"-","forceOpen":"true","guaranteedStop":"false","orderType":"MARKET","size":"0.04","stopDistance":"2","trailingStop":"true","trailingStopIncrement":"1"}

which works.

And the following is the same printout when trying to delete a position:

IgAPI.post: URI: https://demo-api.ig.com/gateway/deal/positions/otc
IgAPI.post: Headers: java.net.http.HttpHeaders@42f3e43d { {_method=[DELETE], Accept=[application/json; charset=UTF-8], Content-Type=[application/json; charset=UTF-8], CST=[removed], IG-ACCOUNT-ID=[removed], Version=[2], X-IG-API-KEY=[removed]} }
IgAPI.post: Body: {"dealID":"DIAAAAPN7BCT8AP","direction":"SELL","size":"0.04","orderType":"MARKET"}

which yields a 404 response.

Any help highly appreciated!
 

Link to comment
  • 0

Thanks! 🙂 Tested and works with version 1. I sort of remember that I changed to version 2 a few months back, but I don't remember why, and the program still seems to work. (That code is also used during log in and creation of position.)

Not sure why that lead to 404, but now I'm past that hurdle. 

Link to comment
  • 0

Looking at the API documentation, it seems that each call has version 1, and maybe other later versions. I assume we ought to use the latest version for a new application, but the older versions remain so things don't break. e.g. You would use version 2 (the latest) to create a position and version 1 (the only one) to close it.

Julian

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • Fits in well with my cycle low expectation  
    • Natural Gas Mode - Impulsive  Structure - Impulse Wave  Position - Wave (iii) of 5 Direction - Wave (iii) of 5 still in play   Details:  Price now in wave iii as it attempts to breach 1.65 wave i low. Wave (iii) is still expected to extend lower in an impulse.   Natural Gas is currently breaching the previous April low, marking a decisive move as the impulse initiated on 5th March continues its downward trajectory, further extending the overarching impulse wave sequence that commenced back in August 2022. This decline is anticipated to persist as long as the price remains below the critical resistance level of 2.012.   Zooming in on the daily chart, we observe the medium-term impulse wave originating from August 2022, which is persisting in its downward trend after completing its 4th wave - delineated as primary wave 4 in blue (circled) - at 3.666 in October 2023. Presently, the 5th wave, identified as primary blue wave 5, is underway, manifesting as an impulse at the intermediate degree in red. It is envisaged that the price will breach the February 2024 low of 1.533 as wave 5 of (3) seeks culmination before an anticipated rebound in wave (4). This confluence of price movements underscores the bearish sentiment prevailing over Natural Gas in the medium term.   Analyzing the H4 chart, we initiated the impulse wave count for wave (3) from the level of 2.012, which marks the termination point of wave 4. Notably, price action formed a 1-2-1-2 structure, with confirmation established at 1.65 and invalidation set at 2.012. The confirmation of our anticipated direction materialized as price breached the 1.65 mark, signifying a resumption of bearish momentum. Presently, there appears to be minimal resistance hindering the bears, thereby reinstating their dominance in the market. It is projected that wave iii of (iii) of 5 will manifest around 1.43, indicative of the potential for the wave 5 low to extend to 1.3 or even lower. This comprehensive analysis underscores the prevailing bearish outlook for Natural Gas in the immediate future.       Technical Analyst : Sanmi Adeagbo Source : Tradinglounge.com get trial here!
    • TXN Elliott Wave Analysis Trading Lounge Daily Chart, Texas Instruments Inc., (TXN) Daily Chart TXN Elliott Wave Technical Analysis   FUNCTION: Trend MODE: Impulsive STRUCTURE: Motive POSITION: Intermediate (1) DIRECTION: Acceleration in wave 3.   DETAILS: Looking for upside in wave 3 as we seem to have had a shallow wave {c} of 2, potentially indicating a strong upward momentum.       TXN Elliott Wave Analysis Trading Lounge 4Hr Chart, Texas Instruments Inc., (TXN) 4Hr Chart TXN Elliott Wave Technical Analysis   FUNCTION: Trend MODE: Impulsive STRUCTURE: Motive POSITION: Wave {i} of 3. DIRECTION: Top in wave {i}. DETAILS: Looking for a pullback in wave {ii} as we top in wave {i} to then look for additional longs, looking for 172$ to provide support. We conducted a detailed Elliott Wave analysis for Texas Instruments Inc. (Ticker: TXN), examining both its daily and 4-hour chart movements. This analysis aims to provide valuable insights into potential future price movements for traders and investors interested in TXN stock.     * TXN Elliott Wave Technical Analysis – Daily Chart* Texas Instruments Inc. is currently exhibiting a strong impulsive trend, characterized by a motive structure placed in Intermediate wave (1). The stock is anticipated to experience acceleration in wave 3 following a shallow wave {c} of 2. This suggests a robust upward momentum, signaling favorable conditions for bullish positions. * TXN Elliott Wave Technical Analysis – 4Hr Chart* On the 4-hour chart, TXN's impulsive trend is further evident, with the stock positioned in Wave {i} of 3. As the stock approaches the top in wave {i}, a pullback is expected in wave {ii}. This corrective phase presents an opportunity for traders to consider additional long positions, with the key support level identified around $172.   Technical Analyst : Alessio Barretta   Source : Tradinglounge.com get trial here!  
×
×
  • Create New...
us