Decrease balance sync
BalanceOutSync¶
Description: Creates or updates a balance withdrawal and keeps the TCP request open until the matching trade:event is broadcast by the trading runtime.
BalanceOutSync is a manager TCP API method for integrations that need the final withdrawal trade payload in the command response instead of accepting an order and waiting for a separate event subscription.
The same credit and projected-margin checks as BalanceOut are applied before execution.
If the initial check fails, the server returns an immediate error and does not reserve a finance order or register a deferred waiter.
SEO¶
BalanceOutSync is the synchronous TCP withdrawal method for ScaleTrade manager API integrations. Use this endpoint when a CRM, payment gateway, cashier, or backoffice connector must subtract account balance and receive the resulting finance trade transaction by order.
Access Control¶
Requires set_accounts_balance 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.
Request Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
| login | int | Yes | Account login ID |
| amount | double | Yes | Negative withdrawal amount |
| comment | string | No | Optional comment. Default: "Finance" |
| order | int | No | Existing finance transaction order to update. If omitted or not found, the server creates a new finance transaction |
| open_time | int | No | Optional open timestamp |
| close_time | int | No | Optional close timestamp |
Request Example¶
{
"command": "BalanceOutSync",
"extID": "withdrawal-req-1001",
"data": {
"login": 1001,
"amount": -150.0,
"comment": "Manual withdrawal"
}
}
Runtime Flow¶
- Handler validates request data.
- Handler calls the same backend path as
BalanceOut. - Backend reserves or reuses the finance
order. - TCP server stores a pending sync waiter by
order,extID, event type and active session. mainLoopprocesses the finance trade and emitstrade:event.- TCP server matches
trade:event.data.orderand sends the matched eventdatato the original TCP session.
The handler returns the usual successful internal status and adds a service __deferred object into response data. TCP transport intercepts this key, registers a pending response and does not send the intermediate handler response to the client.
Success Response¶
On success the response contains only the data object from the matching trade:event; it does not wrap the full event envelope.
{
"extID": "withdrawal-req-1001",
"status": 200,
"data": {
"order": 1242280,
"login": 1001,
"cmd": 8,
"state": 3,
"profit": -150.0,
"comment": "Manual withdrawal"
}
}
Event Matching¶
For a new finance transaction, TCP waits for trade:event with type = EV_RECORD_ADD and matching data.order.
For an existing finance transaction update, TCP waits for trade:event with type = EV_RECORD_UPDATE and matching data.order.
Timeout¶
The default timeout is 5000 ms. If no matching trade event arrives before timeout, TCP returns status = 504 with SYNC_TIMEOUT.
Notes¶
- The method is available to
SESSION_MANAGER,SESSION_ADMIN, andSESSION_DEALER. - The regular
trade:eventbroadcast still exists as part of the platform event stream. - Use
BalanceOutwhen an immediate accepted-command response is enough. - Credit is not withdrawable. Group policy only determines whether it may support the remaining margin. See Credit and Withdrawal Policy.