Add credit sync
CreditInSync¶
Description: Creates or updates a credit-in operation and keeps the TCP request open until the matching trade:event is broadcast by the trading runtime.
CreditInSync is a manager TCP API method for integrations that need the final credit trade payload in the command response instead of accepting an order and waiting for a separate event subscription.
SEO¶
CreditInSync is the synchronous TCP credit grant method for ScaleTrade manager API integrations. Use this endpoint when a CRM, cashier, or backoffice connector must add broker credit 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 | Positive credit amount |
| comment | string | Yes | Description or reason for the credit |
| 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": "CreditInSync",
"extID": "credit-req-1001",
"data": {
"login": 1001,
"amount": 300.0,
"comment": "Promotion credit"
}
}
Runtime Flow¶
- Handler validates request data.
- Handler calls the same backend path as
CreditIn. - 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": "credit-req-1001",
"status": 200,
"data": {
"order": 1242281,
"login": 1001,
"cmd": 7,
"state": 3,
"profit": 300.0,
"comment": "Promotion credit"
}
}
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
CreditInwhen an immediate accepted-command response is enough. - Credit is non-withdrawable broker collateral and remains separate from balance. See Credit and Withdrawal Policy.