Close Trade Sync
MngCloseTradeSync¶
Description: Closes an existing trade and keeps the TCP request open until the matching runtime trade:event is broadcast by the trading runtime.
MngCloseTradeSync is useful for CRM, backoffice, dealing, and integration flows that need the resulting trade event payload in the command response instead of receiving only an accepted close acknowledgment.
SEO¶
MngCloseTradeSync is the synchronous TCP close trade method for ScaleTrade manager API integrations. Use this endpoint when a CRM, dealer plugin, backoffice tool, or trading connector must close a trade and receive the resulting close trade event payload by order.
Request Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
| login | int | Yes | Account login to which the trade belongs |
| order | int | Yes | Trade order ID to close |
| volume | int | No | Requested close volume. Omit or pass the current position volume for full close. Pass a lower volume for partial close. |
| close_price | double | No | Optional requested close price |
| close_time | int64 | No | Optional requested close timestamp |
| expiration | int64 | No | Optional expiration value |
| comment | string | No | Optional close comment |
| __access | object | Yes | Manager/session access object |
Request Example¶
{
"command": "MngCloseTradeSync",
"extID": "close-sync-1",
"data": {
"login": 123456,
"order": 1001234,
"volume": 500,
"close_price": 1.205,
"__access": {
"type": 2
}
}
}
Runtime Flow¶
- Handler validates the same request fields as
MngCloseTrade. - Backend queues the close trade request.
- TCP stores a pending sync waiter by
order,extID, event type and active session. mainLoopprocesses the close request and emitstrade:event.- TCP matches
trade:event.data.orderand returns the matched eventdata.
Success Response¶
On success the response contains only the data object from the matching trade:event.
{
"extID": "close-sync-1",
"status": 200,
"data": {
"order": 1001234,
"login": 123456,
"symbol": "EURUSD",
"cmd": 0,
"state": 3,
"volume": 500,
"profit": 42.5
}
}
Event Matching¶
For a full close, TCP waits for trade:event with type = EV_RECORD_CLOSE_TRADE
and matching data.order.
For a partial close, TCP waits for the original position update event:
type = EV_RECORD_UPDATEdata.orderequals the original position order
The generated partial-close history record is emitted as a separate close trade
event with a new order and parent_order equal to the original position order.
Timeout¶
The default timeout is 5000 ms. If no matching trade event arrives before timeout, TCP returns status = 504 with SYNC_TIMEOUT.
Notes¶
- Full and partial close requests use the same command.
- Partial close returns the updated original position event. The separate
TS_CLOSED_PARThistory record can be read from trade history after the update event. - Use
MngCloseTradewhen an immediate accepted-command response is enough.