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

  • Like 1
  • 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

    • after last weeks sell off'  a chart showing price in a possible discount & at a previous level of interest 
    • Solana ($SOL) is facing a challenging period in the market, with its price dropping to $130.56 USD. Here’s a closer look at what’s happening and what might be next for SOL. Recent Price Decline 15.17% Drop in a Month: Over the past month, Solana coin has fallen by 15.17%. This decline reflects the broader market’s pressure on the cryptocurrency. 8.5% Weekly Fall: Just this week, Solana saw an 8.5% drop, a sign that bears are firmly in control. Despite attempts to maintain a bullish outlook, the market seems to have different plans. Critical Support Levels Breakdown of $134 Support: Recently, SOL broke through the $134 support level, raising concerns that further declines could be on the way. Key Support at $122: The $122 level is now under the spotlight. This price point has been tested six times, and many whales view it as crucial. A break below this could push SOL towards $90. But if this support holds, it might set the stage for a bullish turnaround. $100 Support: While the $100 support level is still a bit distant, it’s essential to watch if the current bearish momentum continues. Revisiting this level could spell trouble for Solana. Changing Market Sentiment Shift to Bearish: The overall sentiment around Solana is slowly turning bearish. Since March, SOL has struggled to make new highs, and the current price action suggests that new lows could be coming. Potential Bullish Outcome: However, some analysts believe that if Solana manages to stay above $122 throughout 2024 and 2025, it could be incredibly bullish for the future, possibly leading to significant gains in 2025. Upcoming Breakpoint Event Historical Price Surges: There’s a potential catalyst on the horizon. Historically, Solana has seen price surges two weeks before its annual Breakpoint event. In previous years, SOL surged by 35% in 2021 and 2022, and by 60% in 2023. 2024 Event: With 16 days left until the 2024 Breakpoint event, could we see another rally? Only time will tell. The Importance of $122 Support As Solana approaches the $122 support level, all eyes are on whether it will hold. A break below could lead to further declines, while maintaining this support could bring back some bullish momentum. As always, stay informed, and remember the old adage in crypto: "buy the rumor, sell the news." Keep watching the charts as we near the 2024 Breakpoint event.  
    • One of the prominent cryptocurrency exchange, has maintained its commitment to user security through its Protection Fund. This self-insured fund, designed to safeguard user assets against potential threats such as hacks, fraud, and market volatility, has shown remarkable stability and growth. The fund has consistently maintained a value above $390 million, surpassing Bitget's initial commitment of $300 million. The exchange ability to continues to maintain a reserve ratio well above 150%, indicating a strong buffer against potential risks. The fund's value has shown correlation with Bitcoin's price movements, demonstrating its responsiveness to market conditions. Over the observed period, the fund's value peaked at $424.8 million and reached a low of $350.7 million, showcasing its ability to withstand market volatility while maintaining a substantial baseline. In February, the fund reached an all-time high valuation of over $543 million, coinciding with broader market uptrends. The Protection Fund's portfolio includes high-liquidity cryptocurrencies such as BTC, USDT, and USDC, which contributes to its stability and liquidity. This diversification strategy aims to mitigate risks associated with external market factors. Bitget's approach of self-funding and internally managing the Protection Fund allows for potentially quicker response times in critical situations, as it operates independently of external regulations and approvals. As the cryptocurrency market continues to evolve, the performance and management of such security measures will likely remain a point of interest for both users and industry observers.
×
×
  • Create New...
us