Skip to content

MngCloseTradeSync

Description: Closes an existing trade and returns the applied result of this specific operation in the same TCP request.

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.

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 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

  1. TCP creates a request-local completion latch before dispatch.
  2. The authenticated handler validates access and admits the operation.
  3. The runtime retains the initiating operation context through execution.
  4. The applied result or a known execution error completes only this request. Early completion is retained until response delivery.

Success Response

The response uses the existing trade-event data schema, but contains the snapshot applied by this operation, not a later quote or another request. See Sync completion and response fields for every response field and error format.

{
  "extID": "sync-1",
  "status": 200,
  "data": {
    "order": 1001234,
    "login": 123456,
    "cmd": 0,
    "state": 3,
    "symbol": "EURUSD",
    "reason": 3,
    "cashier_transaction_id": 0,
    "volume": 500,
    "parent_order": 0,
    "closed_volume": 0,
    "partial_close_volume": 0,
    "open_time": 1790950014,
    "close_time": 1790950014,
    "open_price": 1.204,
    "close_price": 1.205,
    "sl": 1.1,
    "tp": 1.25,
    "profit": 500,
    "commission": -1.25,
    "storage": -0.75,
    "comment": "",
    "digits": 5,
    "expiration": 0,
    "update_time": 1790950014
  }
}

Operation Correlation

The result is correlated to the internal operation context and this request's completion latch. Matching an order number or receiving an ordinary quote update cannot complete the request. No broadcast subscription is required. Command access checks and broadcast recipient filtering remain unchanged. A full close returns the closed original ticket; a partial close returns the reduced original position. The separate partial-close history ticket does not complete the parent request.

Timeout

The default completion deadline is 5000 ms, measured from TCP worker dispatch. Known execution failures return their mapped error without waiting for that deadline. If no result completes within the deadline, TCP returns 504 SYNC_TIMEOUT. A timeout does not cancel execution or prove that no mutation occurred; inspect the trade and traces before retrying. See Sync completion for complete error examples.

Notes

  • Full and partial close requests use the same command.
  • Partial close returns the updated original position event. The separate TS_CLOSED_PART history record can be read from trade history after the update event.
  • Use MngCloseTrade when an immediate accepted-command response is enough.