Skip to content

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 deposit method for ScaleTrade manager API integrations. Use this endpoint when a CRM, bonus system, cashier, or backoffice connector must add account credit and receive the resulting finance trade transaction by order.

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

  1. Handler validates request data.
  2. Handler calls the same backend path as CreditIn.
  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": "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, and SESSION_DEALER.
  • The regular trade:event broadcast still exists as part of the platform event stream.
  • Use CreditIn when an immediate accepted-command response is enough.