REST API - open workingorder

2 posts / 0 new
Last post
REST API - open workingorder

After much banging my head against a brick wall, I have managed to open some working orders using linux, curl and the REST API, for example...

curl -o foo -H "X-IG-API-KEY: $KEY" -H "Content-type: application/json; charset=UTF-8" -H "$cst" -H "$xst" "https://$IG_HOST/gateway/deal/workingorders/otc" -X POST -H "version: 2" -d '{ "epic": "KA.D.ADN.CASH.IP", "expiry": "-", "direction": "SELL", "size":"10", "level": "461", "type": "STOP", "currencyCode": "GBP", "timeInForce": "GOOD_TILL_CANCELLED", "goodTillDate": null, "guaranteedStop": "true", "stopDistance": "200", "limitDistance": null }'

I then get the dealReference back
{ "dealReference": "JELURBHZ66MWW3C" }

and confirm with:

And most of the time the confirmation comes back good
"dealStatus": "ACCEPTED",
"reason": "SUCCESS",

HOWEVER - A lot depends on getting the current price. If I did the above code with the price 1p higher, it would fail when i do the /confirms.

If I use the GUI, the Current Level is displayed at the top of the order window. I can get the most recent high and low using /gateway/deal/markets?searchTerm - but how can I get the current price -- so my orders will be accepted?

If you want to buy/sell at

If you want to buy/sell at the current price you may want to use a market order. Have a look at positions/otc instead of workingorders/otc.

Log in or register to post comments