MngCloseTrade¶
Description: Allows a manager to close an existing market trade order. Supports full and partial close operations and optional close control parameters.
This method follows the common Trade Request Lifecycle. A successful response means the close request was accepted into runtime processing.
For local execution, full and partial close admission checks the live order and
stores the request state atomically before returning success. A competing close
while that request is pending returns RET_TRADE_INCORRECT_STATE, not a second
successful acknowledgment. A full-close snapshot with stale remaining volume
returns RET_TRADE_BAD_VOLUME. Read the current position and retry after the
pending operation settles. Final execution remains asynchronous. Dealer-routed
requests retain their separate routing lifecycle. These local admission rules
also apply to MngCloseTradeSync before its execution wait begins.
Stop Out shares this local reservation. An admitted partial close settles before Stop Out may close the remaining position. If Stop Out reserves the order first, a competing manager close is rejected rather than accepted concurrently. Late partial-close results cannot reopen finalized parents; every realized partial closure has a closed child record, without double-counting volume or P/L. The request, response envelope and fields remain unchanged.
Access Control¶
Requires dealer_trades for manager/dealer sessions. The target account must also match the manager groups and brand scope loaded from the cached manager record. Token payload is used only for manager id and session type.
Copy-Follower Manual-Write Checks¶
For SESSION_USER or SESSION_CUSTOMER requests, this mutation applies the
copy-follower manual_trading_mode after the usual account/order ownership
checks. The check applies only when the target account has an enabled follower
profile. Mode 0 rejects all manual writes; mode 1 permits new or non-copied
orders but rejects changes to linked copied orders; mode 2 permits both.
Manager/admin/dealer staff sessions bypass this follower policy.
| HTTP | Error | Message |
|---|---|---|
403 |
COPY_MANUAL_TRADING_DISABLED |
Manual trading is disabled for this copy follower |
403 |
COPY_COPIED_ORDER_MANUAL_FORBIDDEN |
Manual changes to copied orders are disabled for this copy follower |
The command returns the denial for its target login or order without accepting that mutation.
Request Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
login |
int | Yes | Account login to which the trade belongs |
order |
int | Yes | Order ID of the trade to close |
volume |
int | No | Requested close volume. If omitted or equal to current position volume, the server performs a full close. If lower than current position volume, the server performs a partial close. |
close_price |
double | No | Positive explicit closing price. Omit or send zero for market execution. For a partial close, the cached valuation price of the open position is not treated as an explicit price; the calculation loop selects the current executable quote (Bid for BUY, Ask for SELL, with configured execution spread). |
close_time |
int64 | No | Closing time |
expiration |
int64 | No | Optional expiration time |
comment |
string | No | Optional comment |
__access |
object | Yes | Access object with manager session data |
Request Example¶
{
"login": 123456,
"order": 1001234,
"volume": 500,
"close_price": 1.2050,
"close_time": 1629987890,
"expiration": 0,
"comment": "partial close by manager",
"__access": {
"type": 2
}
}
Response Parameters¶
| Name | Type | Description |
|---|---|---|
accepted |
bool | Always true on successful acknowledgment |
order |
int | Order identifier being closed |
state |
int | Accepted request state. TS_CLOSE_REQUEST for full close, TS_PARTIAL_CLOSE_REQUEST for partial close. |
login |
int | Target account login |
symbol |
string | Trade symbol |
cmd |
int | Trade command |
volume |
int | Requested close volume |
Response Example¶
The response fields above are inside data. The TCP envelope contains extID
(string request correlation identifier), status (integer HTTP-style result code)
and data (object). Error data may contain error (string code) and message
(string explanation). This acknowledgment is not an execution-price confirmation.
{
"extID": "MngCloseTrade_example",
"status": 200,
"data": {
"accepted": true,
"order": 1001234,
"login": 123456,
"symbol": "EURUSD",
"cmd": 0,
"volume": 500,
"state": 19
}
}
Close Volume Semantics¶
MngCloseTrade uses the same command for full and partial close:
Request volume |
Runtime behavior |
|---|---|
| omitted | Full close of the current remaining position volume |
| equal to current position volume | Full close |
| lower than current position volume | Partial close |
| greater than current position volume | Rejected with bad volume error |
For a partial close, the original position remains open with a reduced
remaining volume. The server creates a separate closed history record with:
state = TS_CLOSED_PARTvolumeequal to the closed partparent_orderequal to the original positionorder
The original position keeps:
- remaining
volume - accumulated
closed_volume - open state after runtime processing completes
Event Flow¶
Full close emits a close trade event for the original order.
Partial close emits:
- update event for the original
order - close trade event for the generated partial-close history record
Clients that need the partial-close history record should query closed/history
trades by parent_order or by account history after receiving the update.