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

    • As a believer in the potential of Ordinals and BRC-20 tokens, I'm pumped about the upcoming listing of the TST token on Bitget. This TeleOrdinal marketplace has been a game-changer for me. Before TST, buying and selling Ordinals and BRC-20s felt like navigating a wild west. Now, I can finally trade these unique assets on a secure and user-friendly platform that uses stablecoins - a massive upgrade.   This is exactly what the Ordinals and BRC-20 space needs: a safe and reliable marketplace to attract new users and fuel further innovation. Huge props to TeleOrdinal for building this, and even bigger props to Bitget for recognizing its potential. TST listing is a major step forward for the entire NFT and Ordinals ecosystem. Can't wait to see what the future holds.
    • MetalCore sounds like a thrilling sci-fi MMO with giant mechs and strategic battles. MetalCore offers some unique features that stand out like pen-World Exploration, explore the war-torn planet Kerberos and uncover secrets beyond just battlefields, choice and Factions, by Selecting a faction with a unique ideology and playstyle to shape your experience and deep Crafting System, with a build and customize your arsenal of mechs, vehicles, and war machines for maximum impact also includes baronies and Guilds form powerful player-driven guilds to pool resources and dominate the battlefield together. So, is MetalCore the ultimate open-world mech MMO with Play-to-Earn because it got listed on Bitget? What do you think? Is MetalCore the future of mech combat MMOs, or just another contender? Have you explored any other mech combat games or Play-to-Earn projects? Share your thoughts in the comments!
    • Silver Elliott Wave Analysis Function -Counter-Trend Mode - Corrective Structure -Double Zigzag for wave B (circled) Position - Wave (Y) of B Direction - Wave (Y) of B is still in play Details - After violating the last update, we have a new outlook on daily and H4 that better fits the current price action. A lower extension is now expected for Silver. Silver Elliott Wave Analysis: Extended Decline and Bullish Outlook Overview: The decline in Silver that began on May 20th is continuing to extend lower and is expected to persist before finding significant support. Despite this downturn, the year-long trend remains bullish and is anticipated to resume once this corrective phase concludes. The emerging chart pattern suggests a further decline towards $27 in the coming days or weeks.   Daily Chart Analysis: Two key observations can be made on the daily chart: Bullish Yearly Trend: The trend for this year has been bullish, leading to a breakout from a prior 13-month sideways price action. This indicates strong underlying bullish momentum. Corrective Decline: The current decline from April 19th, 2024, is identified as corrective. Therefore, the expectation is that the bullish trend will resume once this corrective structure concludes.   To determine when the corrective structure will finish, it’s important to identify the emerging pattern. Early analysis suggests that the price might be forming a double zigzag Elliott wave corrective structure, labeled as waves (W)-(X)-(Y). Wave (W) and wave (X) completed on June 13th and June 21st, respectively. The price is now breaking down in wave (Y), which could extend to $27 or lower. Meanwhile, the year-long impulse is labeled as wave A (circled) in the primary degree, and the double zigzag pullback should complete the corresponding primary degree wave B (circled). Following this, wave (C) is expected to push the price to a fresh 2024 high.   H4 Chart Analysis: The H4 chart provides a detailed view of the sub-waves within the double zigzag structure. The price is currently in wave A of (Y), which is expected to be followed by a minor corrective bounce for wave B. Afterward, the price should continue lower for wave C, completing wave (Y) of B (circled). This pattern aligns with the broader expectation of a corrective phase before the resumption of the bullish trend.   Summary: Current Decline: Silver’s decline from May 20th is expected to continue towards $27 before finding support. Bullish Yearly Trend: Despite the current downturn, the overall trend for the year remains bullish. Corrective Structure: The decline is forming a double zigzag Elliott wave corrective structure. Daily Chart Insight: The trend is expected to resume higher after the completion of the current wave B. H4 Chart Detail: Sub-waves show a minor bounce expected before a further decline to complete wave (Y) of B. In conclusion, while Silver is currently experiencing a corrective decline, the long-term bullish trend is anticipated to resume once this phase concludes. Traders should watch for a potential bottom around $27 and prepare for a renewed bullish impulse towards new highs in 2024. Technical Analyst : Sanmi Adeagbo Source : Tradinglounge.com get trial here!  
×
×
  • Create New...
us