Message schema
The messages the trading services exchange are defined once, as Protobuf, in apps/gateway/proto. The code that reads and writes them is generated from these definitions.
Files
| File | Content |
|---|---|
events.proto | Event, the message of the trading events, with the state of a position, transaction, account or order it carries |
live.proto | Values that follow the market: Quote, QuotesBatch, PositionStatus, AccountBalance, and the progress and status of a prop challenge |
commands.proto | The commands a trading app sends over the WebSocket of live-edge |
replay.proto | What the engine answers live-edge when it reads events from the engine |
In events, amounts and prices are decimal strings and times are google.protobuf.Timestamp. A status, a side and similar values are strings with the values the REST API uses.
A command is sent as JSON: an object with the fields of its message and messageType set to the name of the message. live-edge only accepts the commands of commands.proto and answers any other with an error message. The fields of a command are not checked against the schema.
live-edge sends the messages of live.proto about an account as Protobuf. A client that sets format to json in its Login gets them as JSON instead, with messageType set to the name of the message.
Generated code
Each service holds the generated code for the messages it uses. The generated code is committed.
| Service | Directory | Messages |
|---|---|---|
fix-positions | protos/ | Event, the messages of replay.proto and the live values |
signals | protos/ | Quote |
live-edge | src/schema/ | All |
history | src/schema/ | Quote |
| Cashier backend | src/schema/ | Event and PositionStatus |
packages/wintrado-api | src/schema/ | All |
buf.gen.yaml lists which messages a service gets. The TypeScript code needs @bufbuild/protobuf at runtime, the Go code google.golang.org/protobuf.
Changing a message
- Edit the
.protofile. - Run
make schemainapps/gateway. It checks the definitions and generates the code. It needs Go and Node.js 22 or later. - Commit the definitions together with the generated code.
The pipeline job Trading Schema generates the code again and fails if it differs from what is committed.
Services are deployed one after the other, and the event stream keeps messages for 7 days. A changed message therefore has to stay readable for code that has the previous definition. Add fields under new numbers. Do not change the number or the type of a field, and do not use the number of a removed field again.