Order Management
3 tools in this category.
Overview
Order Management includes 3 tools for this workflow area.
Available tools: cancel_order, modify_pending_order, partial_close.
Use the parameter tables and examples below as the canonical request contract.
cancel_order
Cancels a pending (limit or stop) order by ticket. Defaults to dry_run=true — set dry_run=false to execute live. Returns ORDER_NOT_FOUND if the ticket is not in pending orders. Requires the trade capability and inp_AllowTrading=true on the EA.
Leases: if another agent holds a lease (see acquire_lease / get_leases) on this ticket or its symbol, the call is refused with code LEASED and current_state {resource, holder, expires_at} unless you pass that lease's lease_token. Nothing is changed when refused.
This tool can affect a live trading account. dry_run defaults to true — pass dry_run: false explicitly to execute for real.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
ticket | integer | Yes | — | — |
lease_token | string | No | — | Token from acquire_lease for the ticket or symbol you are acting on. Required if another agent holds a lease on it, otherwise ignored. |
dry_run | boolean | No | true | — |
Example Request
{
"tool": "cancel_order",
"arguments": {
"ticket": 123456,
"dry_run": true
}
}Usage Notes
- Keep
dry_run: trueuntil you have validated symbol, lot size, and expected execution behavior.
modify_pending_order
Modifies the price, stop_loss, take_profit, or expiry of a pending (not-yet-filled) order. Distinct from modify_position (trading.ts), which adjusts stop_loss/take_profit on an already-open position — use this tool for a ticket still showing in get_orders, that one for a ticket in get_positions. At least one of price, stop_loss, take_profit, or expiry must be provided. expiry is unix epoch seconds (UTC) and must be in the future; pass 0 to clear the expiry (good-till-cancelled). Milliseconds are rejected. A live modify returns the stored expiration and type_time, plus a warning if the server stored a different expiration; verify with get_orders (expiration, epoch seconds, 0 = none). Defaults to dry_run=true — set dry_run=false to execute live. Requires the trade capability and inp_AllowTrading=true on the EA.
Leases: if another agent holds a lease (see acquire_lease / get_leases) on this ticket or its symbol, the call is refused with code LEASED and current_state {resource, holder, expires_at} unless you pass that lease's lease_token. Nothing is changed when refused.
This tool can affect a live trading account. dry_run defaults to true — pass dry_run: false explicitly to execute for real.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
ticket | integer | Yes | — | — |
price | number | No | — | — |
stop_loss | number | No | — | — |
take_profit | number | No | — | — |
expiry | integer | No | — | Unix epoch seconds (UTC), in the future; 0 clears the expiry. |
lease_token | string | No | — | Token from acquire_lease for the ticket or symbol you are acting on. Required if another agent holds a lease on it, otherwise ignored. |
dry_run | boolean | No | true | — |
Example Request
{
"tool": "modify_pending_order",
"arguments": {
"ticket": 123456,
"dry_run": true
}
}Usage Notes
- Keep
dry_run: trueuntil you have validated symbol, lot size, and expected execution behavior.
partial_close
Closes a portion of an open position. volume must be less than the full position volume. Defaults to dry_run=true — set dry_run=false to execute live. Returns INVALID_PARAMETER if volume >= position volume, POSITION_NOT_FOUND if position closed between dry-run and live call. On MT5 the position keeps its ticket after a partial close: the live response carries position_ticket (the same ticket) and remaining_volume (lots still open); there is no new remaining ticket. Requires the trade capability and inp_AllowTrading=true on the EA.
Optional preconditions for safe concurrent use: expect_sl and expect_tp (prices; 0 = none set), expect_volume (lots) and tolerance_points (price slack in points, default 0). If the position no longer matches, nothing is changed and the call returns code PRECONDITION_FAILED with current_state {ticket, symbol, sl, tp, volume} so you can re-read and decide. With dry_run=true a mismatch is reported the same way and a match adds preconditions_ok. Requires an up-to-date EA build; an older build is refused with ea_upgrade_required rather than skipping the check.
Leases: if another agent holds a lease (see acquire_lease / get_leases) on this ticket or its symbol, the call is refused with code LEASED and current_state {resource, holder, expires_at} unless you pass that lease's lease_token. Nothing is changed when refused.
This tool can affect a live trading account. dry_run defaults to true — pass dry_run: false explicitly to execute for real.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
ticket | integer | Yes | — | — |
volume | number | Yes | — | — |
expect_sl | number | No | — | Stop-loss price you believe the position has now; 0 means 'no stop-loss is set'. Mismatch → PRECONDITION_FAILED, nothing changed. |
expect_tp | number | No | — | Take-profit price you believe the position has now; 0 means 'no take-profit is set'. |
expect_volume | number | No | — | Volume in lots you believe the position has now. |
tolerance_points | integer | No | — | Price slack in points applied to expect_sl / expect_tp (default 0 = exact match to within half a point). Not applied to expect_volume. |
lease_token | string | No | — | Token from acquire_lease for the ticket or symbol you are acting on. Required if another agent holds a lease on it, otherwise ignored. |
dry_run | boolean | No | true | — |
Example Request
{
"tool": "partial_close",
"arguments": {
"ticket": 123456,
"volume": 1,
"dry_run": true
}
}Usage Notes
- Keep
dry_run: trueuntil you have validated symbol, lot size, and expected execution behavior.