Broker API HubMenu

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.

Independent and unofficialNewest check

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 platformEndpointWhat the record says it doesSource
Capital.comDELETE/api/v1/positions/{dealId}Close an open position by dealId. Confirm the close with GET /api/v1/confirms/{dealReference}.open-api.capital.comchecked
eToroPOST/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
eToroPOST/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
IGDELETE/positions/otcClose 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 APIPOST/mtr-api/{SYSTEM_UUID}/position/closeClose an open position, named by its positionId with its instrument, side and volume.app.theneo.iochecked
Match-Trader Platform APIPOST/mtr-api/{SYSTEM_UUID}/position/close-partiallyClose part of an open position by giving the volume to take off.app.theneo.iochecked
OANDAPUT/v3/accounts/{accountID}/positions/{instrument}/closeClose out the long side, the short side or both for one instrument.developer.oanda.comchecked
OANDAPUT/v3/accounts/{accountID}/trades/{tradeSpecifier}/closeClose a trade in full or in part.developer.oanda.comchecked
TradeLocker APIDELETE/trade/accounts/{accountId}/positionsPlace 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 APIDELETE/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.

APICallWhat the record says it doesSource
cTrader Open APImessageProtoOAClosePositionReq cTrader Open APICloses 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
Derivmessagesell Deriv WebSocket APISells 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() MQL4Closes an open order, in full or for a given number of lots, at a price you pass.docs.mql4.comchecked
MetaTrader 4 (MQL4)functionOrderCloseBy() MQL4Closes an open order against another open order in the opposite direction.docs.mql4.comchecked
MetaTrader 5 (Python package and MQL5)functionorder_send() MetaTrader5 Python packageSends 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() MQL5Sends 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.

Brokers and platforms with no endpoint records at all are not listed above. The broker directory shows what is recorded for each.

Sections