Skip to content

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.

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.

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

  1. Handler validates request data.
  2. Handler calls the same backend path as BalanceOut.
  3. Backend reserves or reuses the finance order.
  4. TCP server stores a pending sync waiter by order, extID, event type and active session.
  5. mainLoop processes the finance trade and emits trade:event.
  6. TCP server matches trade:event.data.order and sends the matched event data to 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, and SESSION_DEALER.
  • The regular trade:event broadcast still exists as part of the platform event stream.
  • Use BalanceOut when an immediate accepted-command response is enough.