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

    • Hi @neueneuen Thanks for coming back to this, Please note that number 1 above has been confirmed, unfortunately, I don't have number 2 yet. We will keep you updated. Thanks, KoketsoIG
    • Just recently, I wrote an article about how a Solana blockchain art project (Artrade) is helping artists raise their earnings and even further transforming their physical works into RWA essentially NFTs. With that in mind, I came across Rarible, a marketplace that focuses on digital art and NFTs and the similarities of the platforms caught my attention. Rarible allows artists to sell their creations as NFTs, essentially digital certificates of ownership and cuts out middlemen, connecting artists directly with buyers. Beyond trading, Rarible offers a somewhat user-friendly interface for creating NFTs, even for beginners.   The platform unlike Artrade is built on the Ethereum blockchain and uses its own token, RARI, for governance and rewarding active users. In the long term they seem building with the goal of becoming a DAO in the future While it’s still early days, I have no doubt Rarible offers a unique approach to buying, selling, and creating digital art, and the recent listing on Bitget will further expose it to new communities and potential investors.     Do you think RARI's approach will be sustainable as a marketplace for NFTs?
    • Soybeans Elliott Wave Analysis  Function - Trend  Mode - Impulse  Structure - Impulse for (5)  Position - Wave 1 of (5) Direction - Wave 2 of (5) Details - Wave 1 of (5) completing with a diagonal. Wave 2 bounce is emerging before the price turns downside for 3 of (5). Invalidation now at 1226’6. Not much has changed since the last update.   Soybean Price Analysis: Elliott Wave Perspective Signals Continued Downward Trend   In the realm of commodity trading, Soybean has recently undergone a significant downturn, marking a nearly 7% drop since March 21st. This decline appears to be part of a broader trend that commenced back in June 2022. However, before this recent descent, there was a brief period of respite characterized by a corrective bounce starting in late February.    Delving deeper into the price action, an Elliott Wave analysis sheds light on the intricacies of Soybean's movement. The daily chart's decline since June 2022 reveals a corrective pattern, delineated into waves A-B-C, as denoted by blue annotations.   The initial wave, labeled as Blue Wave 'A', terminated at 1249 in October 2023, exhibiting a distinct diagonal pattern. Subsequently, a modest rebound ensued, marked by Blue Wave 'B', which concluded at 1398 in November 2023. However, the ascendancy was short-lived as the bears regained control, manifesting in the ongoing development of Blue Wave 'C'. This wave, evolving into an impulse wave, has currently progressed to wave (5) following the completion of wave (4) in March 2024.   Zooming in on the H4 chart, a granular analysis reveals the sub-waves of wave (5). Wave 1 of (5) concluded with a diagonal structure, followed by a corrective phase as the price undergoes a temporary upside correction to complete wave 2. Despite uncertainties regarding whether wave 2 has fully concluded or will undergo another upward leg, the overarching trajectory remains clear – a downward break is anticipated to continue wave 3 of (5), leading to further downside movement.   In light of this analysis, the prevailing sentiment favors sellers, who continue to assert dominance over the commodity market. As long as the price remains below 1226’6, the outlook remains skewed towards further downside potential, with the possibility of reaching the lowest price point since November 2020.   In conclusion, the Elliott Wave perspective offers valuable insights into Soybean's price dynamics, signaling a continued bearish trajectory in the near term. While short-term fluctuations may occur, the broader trend suggests that sellers are likely to maintain control, shaping the commodity's price action in the foreseeable future.   Technical Analyst : Sanmi Adeagbo   Source : Tradinglounge.com get trial here!        
×
×
  • Create New...
us