Close a position
close_positionCloses a position on the user's real broker account (or demo), whole or by volume. Sent twice it opens the opposite position, so reuse an idempotency_key only to retry the same close. Example: {"account_id": "", "position_id": "", "idempotency_key": ""}
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"account_id": "<account_id>",
"position_id": "<position_id>",
"idempotency_key": "<idempotency_key>"
},
"name": "close_position"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| volume | No | Optional: how much to close. Omit to close the whole position. In lots, preferably as a string: "0.01" is a micro lot, "1.00" a standard lot. | |
| comment | No | Optional note stored on the order. MT5 keeps the first 17 characters after our reference. | |
| account_id | Yes | The fxapis account id (a UUID) from list_accounts — not the MT5 login number. | |
| position_id | Yes | The position ticket: `brokerPositionId` from list_positions. | |
| client_order_id | No | Optional reference of your own, echoed back on the order. | |
| idempotency_key | Yes | A unique string you generate for THIS action, e.g. a fresh UUID. If a call fails or times out and you retry the same action, send the SAME key: fxapis then returns the first result instead of acting twice. Use a new key only for a genuinely new action. | |
| deviation_points | No | Maximum slippage in points. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| order | Yes |