Close a position: broker API endpoints compared
10 documented calls from 6 of the 12 APIs with endpoint records here, and 6 functions and messages from 4 APIs whose interfaces are not HTTP, each with the page it was read on.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
What this task is
Closing a position ends your exposure in a market, in full or in part. Some APIs have a dedicated closing call. Others expect an opposite order of the same size, in which case the order placing call is the one to read.
Closing is a dealing request like any other: it can be rejected, and it counts against any allowance for trading calls. Confirm the result before you record the position as closed.
The documented endpoint, API by API
Ordered by the name of the broker or platform API, then by path. The order is not a ranking. Open a row for the parameters, the response and a sample request.
| Broker or platform | Endpoint | What the record says it does | Source |
|---|---|---|---|
| Capital.com | DELETE/api/v1/positions/{dealId} | Close an open position by dealId. Confirm the close with GET /api/v1/confirms/{dealReference}. | open-api.capital.comchecked |
| eToro | POST/api/v1/trading/execution/demo/market-close-orders/positions/{positionId} | Closes a whole demo position, or part of it if you pass UnitsToDeduct, at the market rate. A 200 means the close order was submitted, not that it has completed. | api-portal.etoro.comchecked |
| eToro | POST/api/v1/trading/execution/market-close-orders/positions/{positionId} | Closes a real account position at the market rate, in full or by a number of units. A 200 reply means the close order was submitted, not that the position has closed. | api-portal.etoro.comchecked |
| IG | DELETE/positions/otc | Close one or more positions. IG's official Java sample sends a DELETE with a request body; trading-ig sends a POST with the header _method: DELETE for clients that cannot put a body on a DELETE. | labs.ig.comchecked |
| Match-Trader Platform API | POST/mtr-api/{SYSTEM_UUID}/position/close | Close an open position, named by its positionId with its instrument, side and volume. | app.theneo.iochecked |
| Match-Trader Platform API | POST/mtr-api/{SYSTEM_UUID}/position/close-partially | Close part of an open position by giving the volume to take off. | app.theneo.iochecked |
| OANDA | PUT/v3/accounts/{accountID}/positions/{instrument}/close | Close out the long side, the short side or both for one instrument. | developer.oanda.comchecked |
| OANDA | PUT/v3/accounts/{accountID}/trades/{tradeSpecifier}/close | Close a trade in full or in part. | developer.oanda.comchecked |
| TradeLocker API | DELETE/trade/accounts/{accountId}/positions | Place closing orders for every open position on the account, or only those in one instrument. The page says closure is not guaranteed and may not be immediate. | public-api.tradelocker.comchecked |
| TradeLocker API | DELETE/trade/positions/{positionId} | Place an order that closes one open position, in full or in part. The page says closure is not guaranteed and may not be immediate. | public-api.tradelocker.comchecked |
The same task where the interface is not HTTP
Some platform APIs, and the streaming interfaces of some broker APIs, are not sent as HTTP requests. A function is called from a program in its language, and a message is sent over an open connection. None has a method or a path, so each row is labelled with its kind and its interface. A record is put on this page by hand, from what the vendor's page says the call does, and one call can do several jobs, so the same function can be on more than one task page. Ordered by the name of the broker or platform API, then interface, then name.
| API | Call | What the record says it does | Source |
|---|---|---|---|
| cTrader Open API | messageProtoOAClosePositionReq cTrader Open API | Closes an open position, in full or in part. The definition allows it only where the access token has trade permission for the account. | help.ctrader.comchecked |
| Deriv | messagesell Deriv WebSocket API | Sells an open contract back before it ends, by its contract id. price is the least you accept, and 0 means sell at the market. | developers.deriv.comchecked |
| MetaTrader 4 (MQL4) | functionOrderClose() MQL4 | Closes an open order, in full or for a given number of lots, at a price you pass. | docs.mql4.comchecked |
| MetaTrader 4 (MQL4) | functionOrderCloseBy() MQL4 | Closes an open order against another open order in the opposite direction. | docs.mql4.comchecked |
| MetaTrader 5 (Python package and MQL5) | functionorder_send() MetaTrader5 Python package | Sends a trade request from the terminal to the trade server. One call covers a market order, a pending order, a change to an order or position, a cancellation and a close: the request's action field says which. | mql5.comchecked |
| MetaTrader 5 (Python package and MQL5) | functionOrderSend() MQL5 | Sends a trade request to the trade server and waits for its answer. One function covers a market order, a pending order, a change, a cancellation and a close: the action field of the request says which. | mql5.comchecked |
None documented here yet
These APIs have endpoint records on this site, but none is assigned to this task. That describes this dataset. It is not a statement that the API lacks such a call.
- Deriv: none documented here yet
- Interactive Brokers: none documented here yet
- Saxo OpenAPI: none documented here yet
- Trading 212: none documented here yet
- DXtrade APIs: none documented here yet
- MetaApi: none documented here yet
Brokers and platforms with no endpoint records at all are not listed above. The broker directory shows what is recorded for each.