Trading events
Trading events are the record of everything that changed in the trading engine. They are meant for services that keep their own copy of positions, transactions, accounts or orders.
The engine writes an event in the same database transaction as the change it describes. Every committed change has an event, and a change that was rolled back has none.
Reading
Events are published to the topic exchange trading.events with the key <accountId>.<EventType>, for example 42.PositionClosed. The stream trading.events.log is bound to it with # and keeps every event for 7 days.
To start from a known point, read the stream with x-stream-offset. You can also bind a queue of your own to the exchange.
| Property | Value |
|---|---|
content_type | application/x-protobuf |
message_id | The id of the event, the same as eventId in the body |
type | The event type |
timestamp | When the change was committed |
seq header | The position of the event in the record, the same as seq in the body |
group header | The group the account was in when the event was published |
seq grows in the order the changes were committed, across all accounts. Numbers can be missing, but a number is never used twice.
The cashier backend reads the stream this way, see CRM Projection.
Events arrive at least once. After a broker outage the last events can be repeated, in the same order. Keep the highest seq you have handled, store it together with what you wrote for it, and skip every event that is not above it.
From the engine
live-edge serves the Manager API from the events and fills what it missed on the exchange from two endpoints of the engine. They answer with the Protobuf messages of apps/gateway/proto/replay.proto and are not reachable from outside.
| Endpoint | Returns |
|---|---|
GET /admin/events?after=<seq> | The events behind a seq in the order they were committed, with the group each account is in now. limit (1000, at most 5000), types[] and accountIds[] narrow the answer. upTo is the seq up to which the answer is complete. Without after the answer has no events and upTo is the latest seq. |
GET /admin/events/snapshot?state=positions | The open positions and the seq of the last event they include. state=accounts returns the accounts with their balance and credit instead. accountIds[] narrows the answer. |
A request with the scope group-admin only gets the accounts of its groups. /admin/events answers 410 when events behind after are no longer kept, and 409 when after is ahead of the latest event.
Events
| Type | Carries | Written when |
|---|---|---|
PositionOpened | position | A position is opened |
PositionUpdated | position | Anything stored on a position changes: stop loss, take profit, size, the swap charged at rollover, a correction by an admin |
PositionClosed | position | A position is closed. Carries the final swap, commission and profit |
TransactionCreated | transaction | A balance or credit movement is booked, including the result of a closed position |
AccountCreated | account | An account is created |
AccountUpdated | account | The settings of an account change, including its group and a pending withdrawal |
OrderCreated | order | An order is stored, whatever its status |
OrderUpdated | order | An order is filled, rejected, cancelled or assigned to a position |
Events written by one change follow each other directly. A close, for example, writes PositionClosed, OrderUpdated and TransactionCreated.
Body
The body is the Protobuf message Event of apps/gateway/proto/events.proto, see Message Schema. It holds the whole stored state after the change, not what changed. Amounts and prices are strings.
This is a PositionClosed event in the JSON form of the message. A field without a value is left out.
{
"eventId": "5f0c1a52-0d3e-4c53-9a37-3d2f3f1f6a10",
"seq": "48211",
"type": "PositionClosed",
"accountId": 42,
"occurredAt": "2026-03-03T10:00:00.503Z",
"position": {
"id": 7001,
"accountId": 42,
"version": 4,
"symbol": "EURUSD",
"side": "buy",
"size": "100000",
"status": "closed",
"platform": "pro",
"openPrice": "1.08512",
"openedAt": "2026-03-02T09:15:30.123Z",
"closePrice": "1.09012",
"closedAt": "2026-03-03T10:00:00.500Z",
"closeReason": "take_profit",
"closedPL": "500",
"closedPLInAccountCurrency": "500",
"marginRate": "1.08512",
"swap": "0.35",
"commission": "7",
"updatedAt": "2026-03-03T10:00:00.502Z"
}
}
origin is set on transaction and account events. It is what the caller named itself in the request, or wintrado.com/positions for changes the engine made on its own. It is missing when neither applies.
version of a position or account grows by one with each of its events.
Account events carry neither balances, which only change with a transaction, nor the personal details of the holder.
The folder apps/gateway/fix-positions/outbox/testdata/events has an example of every event in its JSON form.
Monitoring
| Metric | Meaning |
|---|---|
wintrado_fix_positions_outbox_pending | Events waiting to be published |
wintrado_fix_positions_outbox_oldest_pending_age_seconds | How long the oldest of them has been waiting |
wintrado_fix_positions_outbox_relay_connected | 0 while there is no broker to publish to |
wintrado_fix_positions_outbox_published_total | Events the broker has confirmed |
Events stay in the table event_outbox until the broker has confirmed them, and for 7 days after that. The latest event is kept beyond that.