External strategy protocol v3¶
Version 3 is a synchronous JSON Lines protocol over child-process standard input and output.
Trading Engine sends initialize, ordered event requests, and shutdown. The strategy answers
with ready, intents, and stopped. It may answer any request with error.
Every message repeats strategy_protocol_version: "3" and a positive canonical
strategy_sequence. A response must repeat the sequence of its request. Only one request is
outstanding. Trading Engine rejects unknown or duplicate fields, invalid canonical values,
oversized lines, a wrong version or sequence, unexpected response types, EOF, timeout, and a
nonzero process exit.
The event context contains the replay clock, a marked base-currency portfolio, all working orders,
and the latest available bar for each instrument. Every callback emitted for a market slice uses
that slice's received_at as now and uses its complete bars and FX vector. The portfolio reports
cash, equity, net, long, short, and gross market value plus every attributed cash ledger and
configured position. Position quantities and weights reflect applied fills. Weights are truncated
toward zero to six decimal places. weights_available is false and all weights are null when
equity is zero or negative.
Matching pauses after each strategy callback. The engine applies the response against the exact account and OMS state exposed by that callback before delivering another callback or considering the next eligible order. Later same-slice contexts include the effects of earlier responses. The eligible-order sequence is fixed at the start of matching, so newly submitted orders wait for a later slice. Cancelling an order before its turn leaves its unused slice capacity available to the next eligible order.
Event payloads cover completed market slices, fills, order updates, and rejected intents. Response intents use the scenario v3 intent shapes.
External replay requires an empty batch schedule and empty streamed intent batches. The engine
records accepted messages in both directions in a deterministic transcript. A response rejected
for invalid JSON, fields, version, sequence, EOF, or size is never stored as an accepted exchange.
Instead, the partial transcript ends with a rejected_strategy_response diagnostic record. Version
1 rejection diagnostics use the shared
diagnostic/v1 contract. The transcript schema narrows that
contract to the strategy.protocol and resource.limit codes in the strategy phase. The record
includes the structured rejection diagnostic and at most the first 256 raw response bytes encoded
as lowercase hexadecimal. observed_bytes counts bytes available when the engine rejected the
response, and truncated reports whether the prefix omits observed bytes. The transcript and audit
journal retain partial files after failure and finalize only after their respective success checks.
message.schema.jsonvalidates individual requests and responses.transcript.schema.jsonvalidates accepted exchanges and rejected-response diagnostics.fixtures/external.scenario.jsonis the batch replay fixture.fixtures/external.scenario.jsonlis its bounded-memory stream form.fixtures/external.strategy.jsonlis the canonical protocol transcript.