Guide · Closes
Close a position. Then confirm.
A close needs the ticket from the position, not the symbol. The API answers, but the truth is the positions list after it.
01Read the ticket
Every open position carries a ticket. Read positions and take the ticket of the one you want to close.
curl https://api.socketrade.com/v2/acc_.../positions \
-H "X-API-Key: $SOCKETRADE_KEY"
{ "positions": [
{ "ticket": 4789544305, "symbol": "EURUSD",
"volume": 0.01, "profit": 12.40 } ] }02Send the close
PositionClose takes the ticket. Use the ticket from the position, not a guess.
curl -X POST https://api.socketrade.com/v2/acc_.../PositionClose \
-H "X-API-Key: $SOCKETRADE_KEY" \
-H "Content-Type: application/json" \
-d '{ "ticket": 4789544305 }'03Confirm it left
Read positions again. The ticket should be gone. Read history to see the closed deal and its profit. Do not use the close response alone as proof.
curl https://api.socketrade.com/v2/acc_.../positions \ -H "X-API-Key: $SOCKETRADE_KEY"
When it fails
404No position with that ticket on this account.
409The position is already closing or closed.
Market closedThe broker refused the close because the market is shut.
TimeoutRead positions before retrying; the close may have gone through.