Trades Event¶
Sent automatically on any trade-related change (open, close, modify, delete, etc.).
There are two formats used depending on context:
Compact WebSocket format (most common)¶
[
"o", // 0: marker "o" = order
58123, // 1: order ticket
100500, // 2: login
"EURUSD", // 3: symbol
0, // 4: cmd (0=buy, 1=sell, ...)
0.10, // 5: volume
1.08952, // 6: open price
0.0, // 7: close price (0 if still open)
1734312000, // 8: open time
0, // 9: close time
1.09500, // 10: TP
1.08000, // 11: SL
0, // 12: state (0=confirmed open, 1=open request, 3=closed)
-12.50, // 13: storage/swap
-3.20, // 14: commission
157.80, // 15: profit (0 if open)
"API trade", // 16: comment
201 // 17: code (201=created, 200=modified, 202=closed, etc.)
]
TCP object format¶
TCP subscribers receive JSON objects, including deletion notifications. Deletion
events capture source metadata before cache removal. A delayed calculated event
whose source metadata is unavailable still contains the calculated fields below;
only the explicitly optional metadata fields are omitted. The server must not
send a bare TRADE_NOT_FOUND string in place of an event.
For calculated close events with source metadata, comment includes the same
protective-close suffix as the finalized record: [SL], [TP], or
[SO ml:<level>%, e:<equity>, m:<margin>]. This holds even when the event is
serialized before TradeManager applies the close result. A finalized source
comment is reused without appending a duplicate suffix. The SO numbers describe
the close activation snapshot, not the account state after closing.
The envelope contains event (string, trade:event), type (integer
EventRecordType: add=0, update=1, delete=2, restore=3, archive=4,
activate=5, close=6, reject=7), and data (object).
| data field | Type | Description |
|---|---|---|
| order | int | Order identifier |
| login | int | Account identifier |
| cmd | int | Trade/finance command |
| state | int | Record state; deletion is 6 |
| symbol | string | Instrument; empty for finance records |
| volume | int | Internal volume units |
| parent_order | int | Parent of a partial-close record, otherwise 0 |
| closed_volume | int | Accumulated closed volume |
| partial_close_volume | int | Requested partial-close volume |
| open_time, close_time | int | Unix timestamps in seconds |
| open_price, close_price | number | Record prices; finance amount is in close_price |
| sl, tp | number | Stop loss and take profit |
| profit, commission, storage | number | Profit, commission and swap components |
| update_time | int | Event record update timestamp; calculated events use the calculation payload |
| reason | int | Optional source metadata: record reason |
| cashier_transaction_id | int | Optional source metadata: linked cashier transaction |
| comment | string | Optional source metadata: comment |
| digits | int | Optional source metadata: precision |
| expiration | int | Optional source metadata: expiry timestamp |
Pending creation confirmation¶
For pending commands 2 (BUY_LIMIT), 3 (SELL_LIMIT), 4 (BUY_STOP) and 5 (SELL_STOP), state 1 is a transient open request, not the stable pending state. The creation event has type 0 and state 0. Before publishing it, the server updates the authoritative TradeManager cache and indexes and schedules the normal asynchronous persistence operation. Manager queries must therefore converge to state 0 unless a subsequent modification, cancellation or activation has changed the order. The event is not a disk-flush acknowledgement.
Confirmation is conditional on the current record still being a pending open request. Duplicate confirmation and stale work must not overwrite a newer cancel/modify request, an activated market order or a final record. An expired request follows the deletion path instead. No request or response fields change; the envelope and all data fields are described above.
Pending synchronization uses internal monotonic revisions; these are not wire fields. Out-of-order notifications are reconciled with the current manager record. A stale confirmation cannot replace a newer cancellation or modification, and a delayed notification cannot recreate a removed or activated pending order. Cancellation and expiration publish a deletion event only after their conditional state transition has been applied. Modification acknowledgements follow the same rule. Activation validates the pending revision at handoff to market admission; this does not change the subsequent market-admission protocol.
Complete pending creation event example:
{
"event": "trade:event",
"type": 0,
"data": {
"order": 1835,
"login": 100047,
"cmd": 2,
"state": 0,
"symbol": "TEST_RULE_SESSIONS",
"reason": 0,
"cashier_transaction_id": 0,
"volume": 20,
"parent_order": 0,
"closed_volume": 0,
"partial_close_volume": 0,
"open_time": 1790766893,
"close_time": 0,
"open_price": 1.09,
"close_price": 0,
"sl": 0,
"tp": 0,
"profit": 0,
"commission": 0,
"storage": 0,
"comment": "",
"digits": 5,
"expiration": 0,
"update_time": 1790766893
}
}
Complete deletion event example:
{
"event": "trade:event",
"type": 2,
"data": {
"order": 1154,
"login": 100011,
"cmd": 6,
"state": 6,
"symbol": "",
"reason": 0,
"cashier_transaction_id": 0,
"volume": 0,
"parent_order": 0,
"closed_volume": 0,
"partial_close_volume": 0,
"open_time": 1790684661,
"close_time": 1790684661,
"open_price": 0,
"close_price": 75.75,
"sl": 0,
"tp": 0,
"profit": 75.75,
"commission": 0,
"storage": 0,
"comment": "matrix comment-only update",
"digits": 2,
"expiration": 0,
"update_time": 1790684662
}
}
Common code values (last element in array)¶
| Code | Meaning |
|---|---|
| 201 | Trade opened |
| 200 | Trade modified |
| 202 | Trade closed |
| 203 | Pending order created |
| 204 | Pending order deleted |
| 410 | Trade deleted (manual) |
| ``` |
See TradeRecord for full field description.