Other languages
The strategy wire’s CSV protocol is small enough to implement in an afternoon, in any language that can read stdin and write stdout. The entire conversation:
you > ALGO/1 protocols=stdio-csv-v1 sdk=my-sdk-0.1 (hello, once)
engine> ALGO/1 use=stdio-csv-v1 run_id=... (selection)
engine> init,RUN_ID,START,END,[SYM:MIC:CLASS:TICK:PV:CCY|...],[NAME:VALUE|...]
you > init_ack,LOOKBACK,[],NEEDS_FILLS,NEEDS_SESSIONS,NAME,DESC,[schema...]
engine> bar,SYMBOL,TS,OPEN,HIGH,LOW,CLOSE,VOLUME[,SERIES_ID]
you > order,SYMBOL,buy|sell,QTY,market|limit|stop|stop_limit|stop_trailing[,PRICE[,STOP_PRICE]]
you > noop (when no order; one response per bar)
engine> fill,CLIENT_ID,SYMBOL,buy|sell,QTY,PRICE,TS,COMMISSION (if you asked for fills)
engine> shutdown,REASON (then exit 0)
you > log,LEVEL,MESSAGE (anytime, before your response)
Rules that bite: every line is flushed immediately; exactly one response line per bar – the CSV wire cannot express multiple orders per bar (or attached/bracket orders); fields cannot contain commas; timestamps are RFC 3339 nanoseconds. If you need multi-order responses or brackets, that is what the protobuf wire is for – in Go you get it free from the SDK. PRICE and STOP_PRICE parse as Go parses a float, so nan, +Inf and Infinity are read; an order whose level is not finite is refused before the venue, price_not_finite: price=NaN, and the strategy reads a cancel line with reason rejected before its next bar (GLE-1090).
v1’s limits. The v1 order line carries neither a label nor a time in force. Two consequences of that are documented limits of v1, pinned by regression tests and kept as they are (v1 does not change):
- A CSV v1 order reaches the simulator with TIF 0 and no client id, so it rests until it fills or the data ends, and its end-of-data cancellation (reason
shutdown) names no client id either. The same order sent asDay, as the Go constructors send it, expires after its first eligible bar. A v1 strategy therefore trades with resting orders that no time in force ends, and the GTC quarter-end rule (GTC quarter-end cancellation) does not reach them either, since it applies toGTCalone. - The Go SDK’s v1 working view keeps a filled CSV v1 order listed as working. The SDK files the order under the label the strategy gave it, but the order line drops the label and the engine’s fill names no client id, so the fill moves
ctx.Positionand leaves the order inctx.WorkingOrders(). This affects a Go strategy run with--strategy-protocol csvon a legacy run; under lifetime v2 the same flag selects stdio-csv-v2, which has no such gap.
TestTcv2V1CSVOrderRestsWithTIFZero and TestTcv2V1DayOrderExpiresAfterOneBar (engine) and TestTcv2V1GoViewStrandsAFilledOrder (sdk/strategy) pin both. stdio-csv-v2 is the fix: its order line carries the label, the attempt and an explicit time in force, and every event names the attempt it concerns (The stdio-csv-v2 grammar).
Complete reference clients live in the repository in nine languages beyond Go: strategies/demo/python/smacross.py (stdlib-only Python), strategies/demo/rust/smacross/ (Rust), strategies/demo/c/smacross/ (C99), strategies/demo/shell/smacross.sh (bash + awk), strategies/demo/cpp/smacross/ (C++17), strategies/demo/ocaml/smacross.ml (OCaml), strategies/demo/r/smacross.R (base R), strategies/demo/haskell/smacross.hs (Haskell, base only), and strategies/demo/julia/smacross.jl (Julia stdlib), each speaking raw stdio-csv-v1 with the indicator math embedded, and each of the nine, the scripting four (Python, shell, R, Julia), the compiled three (C, C++, Rust) and the functional two (Haskell, OCaml), stdio-csv-v2 beside it (The ports under both grammars). They implement the same SMA crossover as the Go version, each keeping its position from the engine’s fill lines as the SDK keeps ctx.Position (the init_ack asks for fills), so every cross after the first reverses through flat (GLE-533). make crosscheck proves every port with an available toolchain produces byte-identical order/noop streams from the same bar fixture – the recommended pattern for porting: pin a decision contract, replay the same fixture (see Testing your strategy), and diff the decisions. The same comparison runs inside go test through conform.Decisions for the Go, Python and shell ports, and for every dual-grammar port (Conformance under both lifetimes).
The ports under both grammars
Since the order-lifetime programme’s increment I21, PR7a (GLE-467, landed 2026-10-11, under the owner’s decision of 2026-10-10), the scripting ports, strategies/demo/python/smacross.py, strategies/demo/shell/smacross.sh, strategies/demo/r/smacross.R and strategies/demo/julia/smacross.jl, are dual-grammar: each speaks stdio-csv-v1 exactly as before under a legacy run and stdio-csv-v2 under lifetime v2, a backtest’s default. PR7b (landed 2026-10-11, algolang PR 183) made the compiled ports, strategies/demo/c/smacross/smacross.c, strategies/demo/cpp/smacross/smacross.cpp and strategies/demo/rust/smacross/src/main.rs, dual-grammar the same way, and PR7c (landed 2026-10-11) the functional ports, strategies/demo/haskell/smacross.hs (GHC base only) and strategies/demo/ocaml/smacross.ml (the OCaml standard library alone), built as before with plain ghc and ocamlopt. All nine non-Go ports speak both grammars. The v1 grammar cannot carry the lifetime-v2 capability, so under lifetime v2 the engine’s v1 codec refuses a port that offers v1 alone before any bar (wire: capabilities [lifetime-v2] are not expressible in stdio-csv-v1; run the strategy on stdio-pb-v1 (GLE-200 I2), followed on a backtest that names no profile by the default’s hint naming --lifetime v1): no port silently inherits a lifetime it does not implement.
The recipe, the same in the nine languages (lifecycle.py is the model of the v2 side, The Python lifecycle fixture):
- Hello. Advertise both grammars:
ALGO/1 protocols=stdio-csv-v1,stdio-csv-v2 sdk=raw-py. The engine picks the first of its preferences the port offers (Negotiating stdio-csv-v2): a lifetime-v2 run offers csv-v2 ahead of csv-v1; a legacy run has no csv-v2 in its list and picks csv-v1, so the v1 stream is as it was. An engine that predates v2 ignores the token. - Branch on
use=.ALGO/1 use=stdio-csv-v1runs the v1 loop unchanged,ALGO/1 use=stdio-csv-v2the v2 loop; any other selection is reported on stderr and exits 1. A first line that is not a handshake line is replay mode, which stays v1 (Raw-CSV replay). - init and init_ack. The v2
initline is the v1 line plus[CAPABILITIES]andBATCH_LIMIT: reuse the v1 init parsing on the first six fields, requirelifetime-v2in the capability list (elseerror,capability_unsupported,...), check that the batch limit is a decimal integer in [1, 2147483647] (one command per batch fits any limit), and answer the v1init_ackline with,[lifetime-v2]appended. - One batch per decision. Make the v1 decision for each
bar(orabar) line, then speak it as a batch committed for the bar’s TS, echoed verbatim: an order becomesorder,sma,N,SYMBOL,SIDE,QTY,market,day,0,0,0,,NAME(the labelsma, N the label’s next attempt, QTY the decision’s quantity, a Day market order, the symbol percent-escaped, no conviction, and NAME the order’s name,LEfor a buy andSEfor a sell, GLE-666) followed bycommit,TS,1; a noop becomescommit,TS,0alone. Aturn,AT,TURN,BUDGETline is answeredcommit,AT,0, and a late bar buffers its close and answerscommit,TS,0. - Warm-up blocks.
warmup,COUNTopens a block of COUNT bar lines: buffer each close with no decision, write nothing until the last, then answercommit,TS,0for its TS; any other line inside the block is a protocol error. - Consume the events. A
fillline (fourteen fields after the verb, or fifteen when it echoes the order’s NAME) moves the position by its quantity, up on a buy and down on a sell, as a v1 fill line does, and takes no reply.update,cancel_responseandcancelledlines (andsession_start,session_end,corpaction,roll) take no reply and change nothing. No line re-submits: a decision is made on a bar alone. - Shutdown. Exit 0 on
shutdown; under v2 the end of the input without a shutdown line is an error (exit 1), where a v1 session ends at EOF.
In each port the v2 side is a grammar adapter of a few dozen lines over the v1 decision core (the Python port’s SmaCrossV2 wraps SmaCross; the shell port’s v2_bar calls its on_bar and reads the decision it left, under bash 3.2; the C port’s on_init and on_bar leave their line in a reply buffer the v1 handler echoes, as the shell port’s do, and its v2_bar parses the order line on_bar left; the C++ and Rust ports’ SmaCrossV2 each hold a SmaCross, with a buffer method split out of on_bar for a warm-up bar, as the Python port’s; the Haskell port’s onBarV2 threads the v1 St inside its V2 record through onBar’s Either, and the OCaml port’s v2_bar calls on_bar on the state its v2 record holds), so the decisions cannot drift between the grammars. In the functional two the one change to the core is the split of the bar handler’s close buffering (bufferClose, buffer) from its decision, so that a warm-up bar can take the first alone. A short example, the Python port’s bar handler:
def on_bar(self, fields):
if self.warmup_left > 0:
self.core.buffer(fields)
self.warmup_left -= 1
return [commit(fields[2], 0)] if self.warmup_left == 0 else []
decision = self.core.on_bar(fields) # "noop" or "order,SYM,side,1,market"
if decision == "noop":
return [commit(fields[2], 0)]
_, symbol, side, qty, _ = decision.split(",")
self.attempt += 1
# No conviction, so its field is empty before the order's NAME.
return ["order,%s,%d,%s,%s,%s,market,day,0,0,0,,%s"
% (LABEL, self.attempt, escape(symbol), side, qty, ORDER_NAMES[side]),
commit(fields[2], 1)]ORDER_NAMES is {"buy": "LE", "sell": "SE"}. The ports’ v1 lines are unchanged: stdio-csv-v1 has no field for a name.
The frozen transcript. internal/wire/testdata/csv2/smacross_sine.txt is one stdio-csv-v2 session of the SMA crossover over the conformance suite’s 96-bar daily sine fixture (strategies/conform/testdata/cf21/sine_1d.csv; Fast 3 and Slow 8, the defaults), recorded once from the engine’s csv2 host driving the Python port: engine.Run under --lifetime v2 through the file-csv adapter, the port behind the suite’s recorder (strategies/conform/testdata/tee, a strategy wrapper that logs each line as it passes, > for the engine’s and < for the port’s), at main 0ae4e816 on 2026-10-11, and reviewed by hand as the two lifecycle transcripts were. It was recorded again on 2026-10-17 (GLE-533), when the ports began to keep their position from the fill lines, and on 2026-10-22 (GLE-666), when they began to name their orders: each order line ends ,,SE or ,,LE and each fill line echoes the name, and the init line offers order-conviction-v1 beside lifetime-v2, as the engine has since GLE-532. Its header records the review: no warm-up block, since the fixture has no bars before the run’s start; ten empty batches while the window fills; eight Day market orders under sma, attempts 1 to 8, a sell on each cross below and a buy on each cross above, at the bars where the v1 decision stream has its order lines; each accepted (update ... working) and filled at the next bar’s open (fill, remaining 0; 105 on a sell and 95 on a buy, the fills of the frozen v1 blotter); no cancel; shutdown,end of data after the last bar’s batch. 255 lines, 221 of them the exchange. The hello’s sdk=raw-py and the init_ack’s SMA Crossover (py) are the Python port’s; the replay test substitutes each port’s token before feeding it, and every other strategy line is replayed byte for byte through every port. go test ./strategies/conform -run TestPr7PortsReplayV2 -record-ports-transcript re-records it (the header is kept; the new exchange is diffed against the old and reviewed).
The tests. Three table-driven tests in strategies/conform/pr7_ports_test.go, each skipped under go test -short and skipping a port whose interpreter or compiler is absent, the three families’ ports rows of the one table (a compiled port’s row builds it into a directory of the test before each run, as the Makefile builds it: cc -O2 -std=c99 and c++ -O2 -std=c++17 for the C and C++ ports, as build-c and build-cpp compile them; cargo’s release build for the Rust port, into the crate’s own target directory, the build make build-rust and the crosscheck share; ghc -O2 with the intermediates under -outputdir for the Haskell port and ocamlopt alone, over a copy of the source, for the OCaml port (ocamlopt writes its .cmi, .cmx and .o beside its input), the functional two memoised by port for as long as the building test runs, so each is built once per test, and the build’s time logged): TestPr7PortsDecisionsV1 (each port’s v1 decision stream over the sine fixture is the Go demo’s byte for byte, through conform.Decisions), TestPr7PortsReplayV2 (each port’s v2 session is the transcript byte for byte, through conform.Replay; the transcript’s own structure is checked first) and TestPr7PortsEngineEndToEnd (each family’s head, the Python port for the scripting family, the C port for the compiled one, the quickest of its family to build, and the OCaml port for the functional one, its build the quicker (0.26 s against ghc’s 0.7 s) and its binary the smaller (1 MB against 13 MB), as the strategy of engine.Run under each profile over the sine fixture: the v1 run negotiates stdio-csv-v1 and the v2 run stdio-csv-v2, and the eight fills agree on symbol, side, quantity, price, timestamp, commission and broker id, with four buys and four sells, equal fill counts in the two lifecycle summaries, and under v2 eight Day market orders under sma and no cancel request; the client id and the order’s name are the fields that differ, since a v1 order line carries neither a label nor a name and a v2 fill echoes both (the test compares the client id); the strategy path the run is given is the port’s command’s last element, the script of a script port or the binary of a compiled one). On this machine the scripting replays take 0.03 s (Python), 0.3 s (shell), 0.2 s (R) and 0.5 s (Julia, its start-up included), the compiled ones 0.3 s (C), 0.8 s to 1.5 s by the machine’s load (C++) and 0.2 s (Rust), each with its build (the C++ compile is most of its figure; cargo’s rebuild is a no-op), and the functional ones 1.1 s (Haskell, 0.7 s of it the build) and 0.6 s (OCaml, 0.26 s the build), the v1 streams about the same, and the three end-to-end pairs, the Python port’s, the C port’s and the OCaml port’s, 0.8 s to 1.9 s each by the load. The Python port’s own tests (strategies/demo/python/smacross_test.py, run by make test) cover the v2 side too and replay the transcript through handle_v2 line for line, so the Python test and the Go test agree on every line; the Rust port’s suite (cargo test, run by make test) does the same through SmaCrossV2::handle. (Conformance under both lifetimes.)
Across a roll (GLE-1505). On stdio-csv-v2 the nine ports take part in the roll rebase, on by default since GLE-1502. Each accepts roll-rebase in its init_ack when the init line offers it ([lifetime-v2|roll-rebase]) and reads a rebase block (Rebase blocks): it takes the block’s closes, writes nothing, and once the last bar has arrived they replace its close window, the newest Slow+1 kept, so its averages are on the incoming contract’s basis. A port keeps no price but its closes, and the position is quantities alone, so nothing else moves. A port that ignored the block would see each roll’s gap as a jump in its closes and cross on it.
internal/wire/testdata/csv2/smacross_rebase.txt is the second frozen transcript: a scripted continuous future, fut:XCME:ES, on its held contract’s prices, 72 daily closes of a sine, two rolls (ESH26 to ESM26 with a gap of +62.5 and a twelve-bar block, ESM26 to ESU26 with −37.25 and a nine-bar block), and the live bars after each cut on the new contract’s prices. No fill line is sent, so every cross trades one unit; the fills are the sine transcript’s to test. The engine lines are made by g1505EngineLines in strategies/conform/gle1505_rebase_ports_test.go and the strategy lines were recorded from the Python port (go test ./strategies/conform -run TestGLE1505PortsReplayRebase -args -record-rebase-transcript). TestGLE1505PortsReplayRebase checks that the file’s engine lines are the generator’s, that the Go demo, whose series the Go SDK restates, makes the transcript’s decisions over the same lines, and that a window that ignores the blocks would decide otherwise; then it replays the transcript through every port byte for byte, as TestPr7PortsReplayV2 replays the sine transcript. The orders fall every ten bars or so, straight through both cuts.
The stdio-csv-v2 grammar
stdio-csv-v2 is the line protocol of the v2 order lifetime (Lifecycle turns) for a strategy written without the Go SDK (GLE-200 increment I10). It carries what the pb wire carries for that lifetime, line for envelope: every submission is an attempt named by a label and an attempt number and has an explicit time in force, the strategy cancels explicitly, and each decision is answered by a command batch (cancels, then orders, then a completion line) where v1 answers each bar with one order line or noop.
Status. Unit 1 (GLE-437) delivered the codec (internal/wire/csv2_strategy.go), three transcripts (internal/wire/testdata/csv2/) and a Python fixture (below); unit 2 (GLE-438) put the grammar on the engine’s strategy wire: the engine host (The engine host) and the Go SDK’s runner (Go over stdio-csv-v2). A run under lifetime v2 offers v2; a legacy run does not (next). GLE-1505 added the roll rebase: a rebase block on a run that rebases, the default since GLE-1502 (Rebase blocks), and futures symbols in the init line’s instrument list.
The conversation, beside v1’s above:
you > ALGO/1 protocols=stdio-csv-v2 sdk=my-sdk-0.1 (hello, once)
engine> ALGO/1 use=stdio-csv-v2 (selection)
engine> init,RUN_ID,START,END,[INSTRUMENTS],[INPUTS],[CAPABILITIES],BATCH_LIMIT
you > init_ack,<the v1 init_ack fields>,[CAPABILITIES]
engine> warmup,COUNT (then exactly COUNT bar/abar lines)
you > commit,FOR,0 (one batch for the whole block)
engine> bar,... or turn,AT,TURN,BUDGET (a decision)
you > cancel,LABEL,ATTEMPT,REQUEST_ID (zero or more, before the orders)
you > order,LABEL,ATTEMPT,SYMBOL,SIDE,QTY,TYPE,TIF,PRICE,STOP_PRICE,TRAIL[,CONVICTION[,NAME[,CANCEL_AT]]] (zero or more)
you > commit,FOR,COUNT (closes the batch)
engine> update / cancel_response / fill / cancelled (events; no answer)
engine> rebase,SYMBOL,SERIES_ID,FROM,TO,CUT,GAP,RATIO,COUNT (rebasing runs only;
then exactly COUNT bar/abar lines; no answer)
engine> shutdown,REASON (then exit 0)
you > log,LEVEL,MESSAGE (anytime but inside a warm-up block)
The codec. internal/wire/csv2_strategy.go has a writer and a parser for each line kind (FormatOrderCSV2 and ParseOrderCSV2, and so on; a parser takes the fields after the verb, as the v1 parsers do), EscapeCSV2 and UnescapeCSV2, and the batch writer and reader, FormatCSV2Batch and ReadCSV2Batch; the reader returns a CSV2Batch, the instant followed by the cancel requests and the orders in line order. wire.StdioCSV2 is the protocol token. Every function is safe for concurrent use and changes none of its arguments, and the v1 codec and its vocabularies are unchanged.
Negotiating stdio-csv-v2
A strategy asks for v2 by advertising the token in its hello line (ALGO/1 protocols=stdio-csv-v2 sdk=raw-py), and the engine answers ALGO/1 use=stdio-csv-v2 when v2 is the first of its preferences the strategy offers. The engine offers v2 only on a run that puts the order-lifetime v2 profile in effect (a backtest’s default, or --lifetime v2), where it inserts stdio-csv-v2 immediately before stdio-csv-v1 in its preference list:
--strategy-protocol | Legacy run | Lifetime v2 run |
|---|---|---|
auto (the default) | stdio-pb-v1, stdio-csv-v1 | stdio-pb-v1, stdio-csv-v2, stdio-csv-v1 |
pb | stdio-pb-v1 | stdio-pb-v1 |
csv | stdio-csv-v1 | stdio-csv-v2, stdio-csv-v1 |
So pb stays the default wherever a strategy offers it, as a Go strategy does, and --strategy-protocol csv runs a Go strategy on v2 (Go over stdio-csv-v2). A strategy that advertises only stdio-csv-v1 still gets v1 under lifetime v2, and its Init then fails with v1’s text, followed on a backtest that names no profile by the default’s hint (Capability negotiation). A legacy run is unchanged: its list has no v2, so a strategy that advertises v2 beside stdio-csv-v1 gets v1, byte for byte, and one that advertises v2 alone is refused at the handshake (wire: no common protocol (...)), as an engine that predates v2 refuses it. The host also refuses a v2 init on a run that does not offer lifetime-v2, before anything is written: engine: <strategy name>: stdio-csv-v2 runs only under order lifetime v2, and this run does not offer lifetime-v2 (GLE-200 I10). A v2 strategy must accept lifetime-v2 on its init_ack (next subsection). There is no v2 replay mode: raw lines piped in without a handshake stay v1 (Raw-CSV replay).
The v2 init and init_ack lines
init,RUN_ID,START,END,[INSTRUMENTS],[INPUTS],[CAPABILITIES],BATCH_LIMIT
init_ack,<the stdio-csv-v1 init_ack fields>,[CAPABILITIES]
Both are the v1 lines with trailing fields, so a port reuses its v1 init parsing. The init line is the v1 line followed by the capability list and the batch limit: seven fields after the verb. The init_ack line is the v1 line (6, 7, 8 or 11 fields after the verb, by v1’s rules) followed by the capability list, which is always the last field.
[CAPABILITIES]is a bracket list, the tokens joined by|;[]is no capability, and the brackets are required. The engine offerslifetime-v2, and the strategy accepts it by listing it. A run also offersroll-rebaseunless the rebase is turned off (GLE-1502); a strategy that accepts it reads rebase blocks (Rebase blocks), and one that leaves it out runs without the rebase, or is refused when the run set--roll-rebaseexplicitly (When the default gives way); a run offersorder-conviction-v1too, which a strategy may leave out. The two lists are judged by the law the pb wire applies (Capability negotiation). A writer renders a token only when it is non-empty and free of,|[]%CR and LF; a reader requires the brackets and non-empty tokens and leaves the rest to that law.BATCH_LIMITis a decimal integer in [1, 2147483647]: the most command lines (cancel lines plus order lines) one batch may carry on this run. The engine announces 256 (wire.CSV2DefaultBatchLimit) on every run and reads every batch against it; no flag or run-config key changes it.- Both lines keep v1’s rules: no escaping, and a value with a CSV metacharacter is refused, as v1 refuses it. One exception (GLE-1505): an instrument’s symbol may contain
:, as every futures symbol does (fut:XCME:ES). Its entry isSYMBOL:MIC:ASSET_CLASS:TICK:POINT_VALUE:CURRENCY, and the other five fields still may not contain:, so a reader takes the last five:-separated fields as those and the rest as the symbol:[fut:XCME:ES:XCME:future:0.25:50:USD]. v1 still refuses such a symbol, so a v1 strategy cannot start on a futures series. Instrument expiration and exchange time zone are dropped frominitsilently, as v1 drops them, so a dated futures run starts and its line is the line without them. - The v2
init_ackcannot expressneeds_calendar,needs_market_eventsorneeds_portfolio, whose data travels only on stdio-pb-v1: anInitAckthat sets any of them is refused, not sent without it. Aligned series are refused as in v1.
From the wait transcript, with a batch limit of 8:
init,lifecycle-wait,2026-06-10T13:29:00.000000000Z,2026-06-10T13:35:00.000000000Z,[MSFT:XNAS:equity:0.01:1:USD],[Mode:wait],[lifetime-v2],8
init_ack,2,[],true,false,CSV v2 lifecycle (py),Submits; observes; cancels and replaces one limit order,[Mode:string:wait:wait;batch],[lifetime-v2]
Identity and request ids
Every v2 command and event line names the attempt first: LABEL (the order’s client_id), then ATTEMPT. The pair is the correlation key.
- On an
orderline LABEL is non-empty and ATTEMPT is at least 1. Attempts are 1-based per label: each physical submission under a label takes the next number, so a replacement under the same label is its next attempt. - A
cancelline addresses one attempt; ATTEMPT 0 addresses the label’s current attempt, the pb wire’s meaning. REQUEST_ID is a non-empty id the strategy chooses (the Go SDK writes<label>/<attempt>/c<n>), and the engine’scancel_responseand thecancelledline that ends the attempt echo it. - The engine’s lines carry what the message holds: an empty LABEL, attempt 0, empty strings and zero numbers go through as they are. ORDER_REF is the engine’s durable reference for the attempt (
sim-Nin a backtest), EXEC_ID the venue’s execution id, the de-duplication key of a partial execution.
The v2 line catalogue
The lines kept from v1 byte for byte, with their v1 layout and rules, are the engine’s bar, abar, corpaction, roll, session_start, session_end and shutdown lines and the strategy’s log,LEVEL,MESSAGE and error,CODE,MESSAGE lines. A log or error line may appear anywhere the strategy may write, inside a batch included, but not inside a warm-up block (Warm-up blocks); it is not a command. v2 does not use v1’s noop and order lines or the engine’s v1 fill, afill and cancel lines: v2’s fill has its own layout, and its cancelled takes the place of v1’s cancel. The v2 lines:
| Line | From | Fields after the verb, in order | Message |
|---|---|---|---|
order | strategy | LABEL (client_id), ATTEMPT, SYMBOL, SIDE, QTY (quantity), TYPE, TIF, PRICE, STOP_PRICE, TRAIL (trail_amount), then CONVICTION (signal.strength) only when the order has one or a name, and NAME (name) only when the order has one | Order |
cancel | strategy | LABEL, ATTEMPT (0 = the label’s current attempt), REQUEST_ID | OrderCancelRequest |
commit | strategy | FOR (the decision’s instant), COUNT (the batch’s command lines) | OrderResponse.for_bar |
warmup | engine | COUNT (the bar lines that follow) | the start of a warm-up BarBatch |
turn | engine | AT, TURN, BUDGET | LifecycleTurn |
update | engine | LABEL, ATTEMPT, STATUS, SYMBOL, QTY (quantity), FILLED (filled_quantity), REMAINING (remaining_quantity), TS (timestamp), ORDER_REF, PARENT (parent_client_id), OWNER (owner_id), BROKER_CODE, REASON, and REPLACES (replaces_attempt) only when it is not 0 | OrderUpdate |
cancel_response | engine | LABEL, ATTEMPT, REQUEST_ID, OUTCOME, STATUS, REMAINING (remaining_quantity), TS (timestamp), ORDER_REF, REASON | CancelResponse |
fill | engine | LABEL, ATTEMPT, SYMBOL, SIDE, QTY (quantity), PRICE, TS (timestamp), COMMISSION, PARENT (parent_client_id), EXEC_ID, ORDER_REF, REMAINING (remaining_quantity), RAW_PRICE, ADJUSTED_PRICE, and NAME (name) only when the filled order has one | Fill |
cancelled | engine | LABEL, ATTEMPT, TS (timestamp), REASON, TRIGGERED_BY, REQUEST_ID, ORDER_REF, REMAINING (remaining_quantity) | OrderCancel |
rebase | engine | SYMBOL, SERIES_ID, FROM, TO, CUT (at_date), GAP, RATIO, COUNT (the bar lines that follow) | RebaseNotice (Rebase blocks) |
The fields:
Text fields (LABEL, SYMBOL, REQUEST_ID, ORDER_REF, PARENT, OWNER, EXEC_ID, TRIGGERED_BY, BROKER_CODE, NAME, REASON on
updateandcancel_response) are escaped (next subsection) and may be empty on the engine’s lines.ATTEMPT, REPLACES, TURN and BUDGET are decimal uint32; REPLACES is at least 1, so a fourteenth
updatefield of 0 is malformed (the writer omits the field then). QTY, FILLED and REMAINING decimal int64 (an order’s QTY may hold any value: the engine’s admission judges it). COUNT is in [0, 2147483647] oncommitand in [1, 2147483647] onwarmup.PRICE, STOP_PRICE, TRAIL, COMMISSION, RAW_PRICE and ADJUSTED_PRICE are finite numbers in decimal or scientific notation (no hexadecimal, no
_, noNaNorInf),0when unused, written in the shortest form that reads back (99.5,0,1e-05). RAW_PRICE and ADJUSTED_PRICE carry the fill’s raw and adjusted prices as they are;0means the same as PRICE.FOR, AT and TS are RFC 3339 instants, written in UTC with nine fractional digits (
2026-06-10T13:31:00.000000000Z) and read in any precision and zone. TS may be empty, which means the message carries no timestamp.REMAINING on a
fillis the quantity still working after the execution, so 0 marks the fill that ends the attempt; on acancelledline it is the quantity still working when the attempt was cancelled.CONVICTION (GLE-532) is the order’s conviction, a finite number written as the prices are (Order conviction), and NAME (GLE-666) the order’s display name (Naming orders). An unnamed order’s line has ten fields, or eleven with a conviction. A named order’s line has twelve, its CONVICTION empty when the order has none: the eleven-field form needs no placeholder, since an order without a conviction is a ten-field line, while the twelve-field form needs the empty slot to place NAME. An empty twelfth field reads as no name. stdio-pb-v1 carries the name as
Order.nameandFill.name; stdio-csv-v1 has no field for it and drops it silently. Afillof a named order echoes the name as a fifteenth field; a fill of an unnamed order, or of no order, such as an expiry settlement, has fourteen:order,sma,1,TEST,sell,1,market,day,0,0,0,,SE fill,sma,1,TEST,sell,1,105,2020-01-12T00:00:00.000000000Z,0,,,,0,0,0,SECANCEL_AT (GLE-1362) is the instant at which the engine requests the order’s cancellation, an RFC 3339 instant as AT is (Order.CancelAt). It is present only when the order has one: the line then has thirteen fields, its CONVICTION and NAME empty when the order has neither, and the thirteenth must not be empty. stdio-pb-v1 carries it as
Order.cancel_at; stdio-csv-v1 has no field for it, and the Go SDK refuses to write such an order there:order,entry,1,TEST,buy,1,limit,gtc,98,0,0,,,2026-03-12T15:01:00.000000000Z
The enumerated fields take lower-case tokens, matched exactly (Buy, GTC and Working are malformed); each token list is in enumeration order, from 0 for STATUS, OUTCOME and REASON and from 1 for the others:
| Field | Tokens |
|---|---|
| SIDE | buy, sell |
| TYPE | market, limit, stop, stop_limit, stop_trailing |
| TIF | day, gtc, ioc, fok |
| STATUS | unspecified, submitting, submission_unknown, working, partially_filled, pending_cancel, held, inactive, filled, cancelled, rejected, denied, expired |
| OUTCOME | unspecified, confirmed, pending, refused, unknown |
REASON (cancelled) | unspecified, oco, tif, explicit, rejected, shutdown, parent_cancelled, gtc_expired, venue, corporate_action, contract_expired, roll, moc_send_missed |
REASON’s tokens oco to gtc_expired, corporate_action and contract_expired are v1’s too (I14 unit 1 added corporate_action and I14 unit 2a contract_expired to both grammars, though only a lifetime-v2 run produces either; Contract expiry (lifetime v2)); v2 adds venue and roll (I15 unit 2a: a cancel a continuous roll made, Order lifetime v2 across a roll; v1 has no token for it, since a lifetime-v2 run does not speak v1) and accepts unspecified, which v1’s parser refuses. Index 10 was reserved for contract_expired from I15 unit 2a until I14 unit 2a took it, so no line ever carried another token there; a reason beyond the table (12 and above) is refused rather than written with an empty field, and an empty REASON is malformed. The engine’s lines are lenient about content and strict about tokens and numbers.
The lifecycle in lines: accepted and working is update STATUS working; held by the race guard is held, REASON beginning held: (The engine race guard); refused by the engine is denied with a REASON, and rejected by the venue rejected with a REASON and a BROKER_CODE; an unknown submission outcome is submission_unknown; a partial fill is partially_filled with fill lines whose REMAINING is above 0, and a full fill the fill line with REMAINING 0; a cancellation is cancel_response OUTCOME confirmed, then cancelled REASON explicit; an expiry is cancelled REASON tif or gtc_expired, or update STATUS expired; a cancel for a corporate action is cancelled REASON corporate_action, and a held order it refuses denied with REASON beginning hold_corporate_action: (Corporate actions and working orders (lifetime v2)); a cancel at a dated futures contract’s expiry is cancelled REASON contract_expired, the venue’s settlement of the position a fill line with an empty LABEL and ATTEMPT 0, and a held order the expiry refuses denied with REASON beginning hold_contract_expired: (Contract expiry (lifetime v2)); an order a continuous roll re-placed is update STATUS working (inactive for a pending child) with REASON roll <from>-><to> and REPLACES the attempt it replaced, a roll’s own cancel cancelled REASON roll, and a held order a roll refuses denied with REASON beginning hold_rolled: (Order lifetime v2 across a roll):
update,entry,4,working,fut:XCME:ES,1,0,1,2026-03-12T21:00:00.000000000Z,sim-9,,,,roll ESH26->ESM26,3
Escaping and fixed arity
Every field of the v2 command and event lines (order, cancel, commit, warmup, turn, update, cancel_response, fill, cancelled) is percent-escaped: % is written %25, , %2C, LF %0A and CR %0D, in upper-case hexadecimal, and every other byte as it is (|, :, ;, ", spaces and non-ASCII bytes included). To read a line, split it on , and decode every field before interpreting it: each % followed by two hexadecimal digits, in either case, becomes the byte they name, and a % without two hexadecimal digits after it is malformed. A needlessly escaped field (%31 for 1) is therefore accepted on every line kind; a writer escapes every field, so its output is canonical. The catalogue’s rejected update shows it:
update,entry,1,rejected,MSFT,5,1,4,2026-06-10T13:31:00.000000000Z,b-1,,,201,price 99.5%2C outside the band; 10%25 limit
whose REASON reads price 99.5, outside the band; 10% limit.
Arity is fixed per verb: a line with more or fewer fields than its layout is malformed. The optional trailing fields are the exceptions. The update line’s fourteenth, REPLACES (I15 unit 2a), is written only when it is not 0, so every other update line is as before; no peer older than the field could meet it, since a lifetime-v2 continuous run, the only run that writes it, was refused until the field existed. The order line’s CONVICTION and NAME and the fill line’s NAME are written only when the order has them, so a line without them is the line it was before; a conviction needs the order-conviction-v1 capability, and the engine writes a fill’s NAME only for an order the strategy named. A refused arity still names the base count: a thirteen-field order line is refused with order line: 13 fields after the verb, want 10, and a sixteen-field fill line with fill line: 16 fields after the verb, want 14. There are no unknown fields, so any other additive change needs a new capability or a new protocol version. The init and init_ack lines and the lines kept from v1 are not escaped and keep v1’s rules.
Command batches
A decision is a bar or abar line outside a warm-up block (FOR is the bar’s close, the line’s TS), a turn line (FOR is its AT), or the end of a warm-up block (below). Every decision gets exactly one batch; no other engine line gets an answer.
A batch is zero or more cancel lines, then zero or more order lines, then exactly one commit,FOR,COUNT line, where COUNT is the number of command lines. It is the pb wire’s answer line for envelope: zero or more OrderCancelRequest envelopes, then one OrderResponse whose for_bar is the decision’s instant. A batch with no commands is the completion line alone, commit,FOR,0, which takes the place of v1’s noop.
- Every cancel line precedes every order line. The engine applies the batch’s cancels first, then its orders, each in line order, and only once the completion line has been read: a batch is applied whole or not at all.
- The batch limit is inclusive: a batch may carry exactly BATCH_LIMIT command lines. A batch with more is rejected whole: the engine stops reading at the first command line beyond the limit, before parsing it, and applies nothing.
- End of input, or a read error, before the completion line yields no batch: nothing of it is applied, and the engine fails the run.
- Any other defect yields no batch either: a line that is not
cancel,orderorcommit(noop, a v1 order line and an empty verb included), a cancel line after an order line, a malformed command line, or a completion line whose FOR is not the decision’s instant (compared as instants, so any rendering of the same instant matches) or whose COUNT is not the number of command lines read. - A writer renders a batch only when every line renders and the batch is within the limit: a strategy that cannot express one order sends nothing rather than half a batch.
An over-bound batch fails the run, as end of input does: it is a programming error, and a rollback line would add state on both sides. A strategy that needs more commands than the limit allows splits them across decisions, as the fixture does under a limit of 1.
Warm-up blocks
warmup,COUNT (COUNT in [1, 2147483647]) starts a warm-up block: exactly COUNT engine lines follow, each a bar or abar line in v1’s layout, with no other engine line among them (no session_start, session_end, corpaction, roll or event line), and COUNT counts those bar lines. The strategy buffers them without a decision and answers the block once, after its last bar, with a batch whose FOR is that bar’s close, as the pb wire answers a warm-up BarBatch with one empty OrderResponse. Several blocks may follow one another, one per symbol or a long warm-up in chunks. A strategy may treat any other line inside a block as a protocol error.
A strategy must write nothing until the block’s last bar. From the warmup line until it has read the block’s last bar line, a strategy writes no line at all, log lines and queued cancels included; once it has read that bar, it answers the block as it answers any decision. The engine writes a whole block before it reads anything, and a block can hold 50,000 bars, far more than a pipe holds (darwin pipes start at 16 KiB). A strategy that writes while the engine is still writing can fill its own output pipe and block on the write, so it stops reading, the engine blocks on the rest of the block, and neither process proceeds.
Rebase blocks
On a run that rebases, the default since GLE-1502 (Re-adjusting at each roll), the engine sends a strategy that accepted roll-rebase one rebase block at each roll of an adjusted continuous series (GLE-1505). It is the pb wire’s RebaseNotice, line for envelope:
rebase,SYMBOL,SERIES_ID,FROM,TO,CUT,GAP,RATIO,COUNT
<COUNT bar or abar lines>
- The
rebaseline has exactly eight fields after the verb, each escaped as every v2 event line is (Escaping and fixed arity). SYMBOL is the logical continuous symbol (fut:XCME:ES); SERIES_ID the series’ id when it is not its symbol, empty otherwise; FROM and TO the outgoing and incoming contracts; CUT the roll’s instant, written as every instant is. GAP is the incoming price less the outgoing one at the cut under panama,0otherwise; RATIO the incoming price over the outgoing one under ratio,1otherwise. Both are finite numbers written as the prices are. A RATIO of0reads as 1, as the SDK reads an unset pb ratio; the codec carries it as it is. COUNT is in [0, 2147483647]. - The COUNT lines that follow are the series’ newest bars on the incoming contract’s basis, oldest first: the history the strategy keeps, now adjusted only by the rolls up to the incoming contract. Each is a
barorabarline in v1’s layout, anabarline for an adjusted bar (a continuous series’ bars are), and is not escaped further. No other engine line comes between them. A block of COUNT 0 is therebaseline alone. - The block comes straight after the roll’s
rollline and before the first bar after the cut. The order at a roll is the same as on pb: therollline, the block, then the roll’s own events. - The strategy answers nothing. As inside a warm-up block, it writes no line from the
rebaseline until it has read the block’s last bar line (Warm-up blocks), and none for the block after it. The next decision is answered as before. - What the strategy does. It restates what it keeps, as the Go SDK does: it replaces the series’ history with the block’s bars, keeping the newest at its own depth, and moves each price it keeps across the roll (an entry price, a stop level, a resting order’s limit) by GAP, or multiplies it by RATIO. Quantities do not change. The engine restates its own copy of every working order on the logical symbol with the same arithmetic, so the strategy’s view and the engine’s agree. A strategy that keeps only a window of closes, such as the demo
smacross, clears the window and refills it from the block. - Errors. The engine fails the run if it cannot write a notice (an empty symbol or contract, no cut, a non-finite gap or ratio, a nil bar), and nothing is written. A strategy may treat a block it cannot read whole as a protocol error: another line inside it, a bar line that does not parse, or the end of its input. The Go SDK does (Go over stdio-csv-v2).
From the language ports’ rebase transcript (internal/wire/testdata/csv2/smacross_rebase.txt), a roll from ESH26 to ESM26 with a gap of 62.5, its block of twelve bars cut to the first two:
roll,fut:XCME:ES,ESH26,ESM26,2026-03-03T22:00:00.000000000Z,62.5,0
rebase,fut:XCME:ES,,ESH26,ESM26,2026-03-03T22:00:00.000000000Z,62.5,1,12
abar,fut:XCME:ES,2026-02-20T21:00:00.000000000Z,5030.25,5039.25,5030,5039,1000,,false,5030.25,5039.25,5030,5039,0,0,ESM26
abar,fut:XCME:ES,2026-02-21T21:00:00.000000000Z,5039,5050.5,5038.75,5050.25,1000,,false,5039,5050.5,5038.75,5050.25,0,0,ESM26
The codec is internal/wire/csv2_rebase.go: FormatRebaseCSV2 writes a notice’s block, refusing an empty symbol, outgoing or incoming contract, a notice with no cut, a non-finite gap or ratio, a nil bar and more than 2147483647 bars, in that order; ParseRebaseCSV2 parses the rebase line’s fields into the notice without its bars and COUNT; and ReadRebaseCSV2 reads the whole block from a line source, growing the bars as the lines arrive rather than from COUNT, so a corrupt COUNT cannot make it allocate. Its errors wrap wire.ErrCSV2Malformed (a bad rebase line, another line inside the block, a bar line that does not parse, which it also wraps) or wire.ErrCSV2Incomplete (the line source failed, or there is none, before the last bar).
stdio-csv-v1 has no grammar for the roll rebase, so the run offers the capability only on stdio-pb-v1 and stdio-csv-v2 (GLE-1502). A stdio-csv-v1 strategy cannot run a continuous futures series in any case: the v1 formatter refuses its Init, because instrument symbol "fut:XCME:ES" is not expressible in stdio-csv-v1. On a wire that cannot carry the rebase, an explicit --roll-rebase refuses the run after Init once it has an adjusted continuous series, with engine: --roll-rebase needs the stdio-pb-v1 or stdio-csv-v2 strategy wire: <wire> has no grammar for the roll rebase (GLE-1505); the run's adjusted continuous series: <labels> (turn roll rebase off with --roll-rebase=false); left at its default, the run goes on without it and says so in a Data note (When the default gives way).
Time in force and what v2 refuses
The time in force is always explicit: an order line’s TIF is day, gtc, ioc or fok, and there is no token for an unspecified one (TIF 0), the time in force every v1 order carries. The Go runner refuses an order without one by name and points to the constructors that set it (Go over stdio-csv-v2).
A writer refuses, rather than drops, what an order line cannot carry: attached orders (brackets), combo legs, an OCO group, the order types MOO, MOC, LOC and STOP_TOUCH, an unspecified type or side, an unspecified or unknown time in force, a non-finite price or conviction, an empty label or symbol, and attempt 0. The parser refuses the same values, and a malformed batch fails the run, as before: the engine’s price_not_finite refusal (GLE-1090) never sees a csv2 order. It carries a conviction and a name (GLE-532, GLE-666), and any text is a valid name. Beyond the order line, v2 does not carry exchange calendars (needs_calendar), declared market events (needs_market_events), the portfolio view (needs_portfolio), aligned series, timers (a batch has no line to arm one; Scheduled decision points), or the account-state, adopted-state and instruments-resolved pushes: a strategy that needs any of them runs on stdio-pb-v1. A continuous futures backtest runs on stdio-csv-v2 as on the pb wire (since I15 unit 2a; since GLE-1505 the init line carries a futures symbol’s :, and a run that rebases sends rebase blocks); with no brackets on the order line, a roll there re-places standalone orders only. v1’s own limits are unchanged.
Error classes
Every error the codec returns wraps exactly one of four sentinels (errors.Is), and a parser’s message names its line’s verb, for example wire: malformed stdio-csv-v2 line: order line: bad attempt "0":
| Sentinel | Text | Returned when |
|---|---|---|
wire.ErrCSV2Malformed | wire: malformed stdio-csv-v2 line | a parser meets a wrong arity, a bad escape, an unknown token, a bad number or instant, an empty label, symbol or request id where one is required, or attempt 0 on an order; the v1 parsers refuse the v1 part of init or init_ack; the batch reader meets a cancel after an order, a completion line that does not match, or another verb |
wire.ErrCSV2NotExpressible | wire: not expressible in stdio-csv-v2 | a writer meets a nil message, a value outside a vocabulary, a non-finite number, a field the line cannot carry, a bad capability token, a count or limit out of range, or needs_calendar, needs_market_events or needs_portfolio; the v1 formatters refuse the v1 part |
wire.ErrCSV2BatchLimit | wire: stdio-csv-v2 batch over its limit | a batch carries more command lines than its limit, or the limit is below 1 |
wire.ErrCSV2Incomplete | wire: stdio-csv-v2 batch incomplete | the input ends, or a read fails, before the completion line; the error also wraps the read error (io.EOF, for one) |
A strategy reports its own failures with v1’s error,CODE,MESSAGE line, as the fixture does with protocol_error and capability_unsupported.
A worked v2 exchange
From internal/wire/testdata/csv2/lifecycle_wait.txt (< lines are the strategy’s, > lines the engine’s; the engine lines illustrate the protocol and are not a recording of one run):
> bar,MSFT,2026-06-10T13:31:00.000000000Z,100.25,100.75,100,100.5,1200
< order,entry,1,MSFT,buy,1,limit,gtc,99.5,0,0
< commit,2026-06-10T13:31:00.000000000Z,1
> update,entry,1,working,MSFT,1,0,1,2026-06-10T13:31:00.000000000Z,b-1,,,,
> bar,MSFT,2026-06-10T13:32:00.000000000Z,100.5,101,100.25,100.75,900
< cancel,entry,1,entry/1/c1
< commit,2026-06-10T13:32:00.000000000Z,1
> cancel_response,entry,1,entry/1/c1,confirmed,cancelled,1,2026-06-10T13:32:00.000000000Z,b-1,
> turn,2026-06-10T13:32:00.000000000Z,1,3
< order,entry,2,MSFT,buy,1,limit,gtc,99.75,0,0
< commit,2026-06-10T13:32:00.000000000Z,1
> update,entry,2,working,MSFT,1,0,1,2026-06-10T13:32:00.000000000Z,b-2,,,,
> cancelled,entry,1,2026-06-10T13:32:00.000000000Z,explicit,,entry/1/c1,b-1,1
> fill,entry,2,MSFT,buy,1,99.75,2026-06-10T13:33:00.000000000Z,0.5,,e-1,b-2,0,0,0
The 13:31 bar is a decision: one GTC buy limit, attempt 1 of label entry, committed with COUNT 1. The engine accepts it (working, reference b-1). At 13:32 the strategy cancels attempt 1 with request id entry/1/c1; the engine confirms it, with the attempt’s status and its remaining quantity as evidence, and grants a lifecycle turn at the same instant (turn 1 of a budget of 3). The strategy answers the turn with the replacement, attempt 2, committed for the turn’s instant. The cancelled line ends attempt 1, echoing the request id, and the replacement fills on the next bar with nothing remaining. In lifecycle_batch.txt the 13:32 batch carries both commands:
< cancel,entry,1,entry/1/c1
< order,entry,2,MSFT,buy,1,limit,gtc,99.75,0,0
< commit,2026-06-10T13:32:00.000000000Z,2
There the venue leaves the cancellation pending, so the race guard holds attempt 2 (update STATUS held) until attempt 1’s cancelled line, then releases it (update STATUS working).
The engine host
engine/stdiohost_csv2.go is the engine’s side of v2, behind the StdioHost and LifetimeHost methods the pb wire uses. A batch is read into the same orders and cancel requests the pb path returns, so the lifetime-v2 driver, the race guard, the admission policy and the transport scheduler apply unchanged, on the simulated and the emulated-live path alike (Lifecycle turns).
- Init. The host writes the v2
initline with the run’s capabilities and the batch limit, 256, reads oneinit_ackline and applies the capability law, as on pb: the strategy must acceptlifetime-v2. - Decisions. A bar goes out as its
barline, or itsabarline when it is adjusted or continuous (v1’s rule), and a lifecycle turn as itsturnline. The host then reads one batch withwire.ReadCSV2Batchat the decision’s instant and returns its cancel requests and its orders, each in line order, as the pb path returns theOrderCancelRequestenvelopes and theOrderResponsethat follows them.loglines are printed on stderr as they arrive ([<strategy name>] LEVEL: message) by the connection’s output drain, whether or not the host is reading a batch, so a strategy whose handlers log heavily through a burst of events cannot deadlock with the engine (since I4 unit 4c, GLE-416, which closes the pipe deadlock GLE-446 recorded for every stdio wire; Cancellation and strategy output), and anerrorline ends the read and fails the run with the strategy’s code and message. - Warm-up. The bars go out in blocks of at most 50,000, the size at which the pb wire splits its warm-up
BarBatchenvelopes. Each block is written whole and flushed once, then answered by one batch at its last bar’s close, read as a decision’s is. Warm-up has no order book and no decision point, so the batch’s cancel requests and orders are discarded with a warning on stderr, as on pb ([<strategy name>] warning: 2 order(s) in a warm-up batch discarded (warmup has no decision point)). A refused batch fails the run at once: no further block is written. - Events. Each
OrderUpdate,CancelResponse,FillandOrderCancelthe driver delivers is oneupdate,cancel_response,fillorcancelledline, formatted by the codec from the values the pb path converts; nothing is read back. Thefillline carries the raw and adjusted prices (v2 has noafill). Thecorpaction,roll,session_start,session_endandshutdownlines are v1’s. - Roll rebases (GLE-1505). On a run that rebases (the default since GLE-1502), at each roll of an adjusted continuous series,
SendRebaseNoticewrites the rebase block, therebaseline and its bar lines, straight after the roll line, and reads nothing back (Rebase blocks). A strategy that did not acceptroll-rebaseis not sent one: an explicit--roll-rebaserefused its run afterinit_ack, and the default runs it without the rebase (When the default gives way). - Failures. A batch the codec refuses fails the run with nothing of it applied: a batch over the limit (the host stops reading at the first command line beyond it), end of input or a read error before the
commitline, and every malformed batch. The error isengine: <strategy name>:followed by the codec’s, which wraps its sentinel (Error classes). An event the grammar cannot carry (a status, outcome or reason outside its vocabulary, or a non-finite number such as a NaN commission) fails the run too, with nothing written: the host refuses rather than corrupt it.
What v2 does not carry. A strategy that needs the account-state, adopted-state or instruments-resolved push runs on stdio-pb-v1.
- The account-state push is skipped, as on v1, so
ctx.Account()keeps its zero value. - The adopted-state push (a live run’s startup reconciliation, when a ledger is configured), the market-events push and the instruments-resolved push are refused with v1’s CSV texts, which name the pb protocol; a declaring strategy (
needs_instruments) is refused before its first bar, as on v1. A non-declaring run gets no instruments-resolved push either, soctx.Instrumentreturns the symbol alone and a strategy’s point value is 1: the SDK booksPosition.Realizedat one currency unit per point, while the engine’s own accounting uses the instrument’s point value. CancelReject: a lifetime-v2 run answers every cancel request with acancel_response, and the host refuses aCancelReject.- The v1 bar exchange (
SendBar,SendBarWithCancels): a v2 decision is answered by a batch, which only the lifetime-v2 loop reads, so a v1 loop that reaches a v2 host is refused before the bar is written. No run configuration routes one there; the refusal guards against a routing defect.
Known limits.
- The log lines a strategy writes on receiving
shutdownreach stderr since GLE-495 (landed 2026-10-11): the child’s stdout is a pipe reaping the child does not close, andShutdownreads it to its end, up to 2 s after the reap, before it returns (Cancellation and strategy output). What remains is the kill path:Closeafter a failed or interruptedShutdown, or without one, kills and reaps the strategy and closes the pipe at once, so what is in the pipe at the kill is lost, as the interrupt of I4 unit 4c accepts. - A strategy that stops answering holds the run until a signal ends it, unless the run sets the strategy stall timeout, which is off by default since a slow strategy on a big bar is not a stall (GLE-496; Stopping a run).
- The data wire is not interruptible: a fetch in progress ignores the run’s cancellation, so a second signal kills the process (GLE-494).
- A live run ended by a signal or a stall returns without its teardown sweep; classifying that exit is I9’s (GLE-469).
- On a live run, an event the grammar cannot carry ends the session where pb would carry it: a broker’s NaN commission, or a status outside v2’s vocabulary, makes the host’s formatter refuse. Settling this is a recorded follow-up, due before stdio-csv-v2 trades at a live venue.
Go over stdio-csv-v2
A Go strategy built on the SDK advertises all three wires, ALGO/1 protocols=stdio-pb-v1,stdio-csv-v2,stdio-csv-v1 sdk=go-0.1.0, so it runs on pb by default and on v2 under --strategy-protocol csv on a lifetime-v2 run (a backtest’s default, or --lifetime v2); an engine that predates v2 ignores the token. The strategy must accept lifetime-v2 (RequiredCapabilities, or SupportedCapabilities for one that serves both profiles), as on pb under lifetime v2. sdk/strategy/run_csv2.go drives the wire with the pb runner’s lifetime-v2 dispatch:
The
initline comes first; a malformed one, a batch limit below 1 included, is answerederror,protocol_error,.... A strategy that setsneeds_calendaris answerederror,csv_unsupported,...with v1’s text, and aninit_ackthe grammar cannot carry with the codec’s.A warm-up block’s bars enter the history without a decision (no
OnBarruns, so nothing is written inside the block), and after the last bar the runner answers the block with a batch of no order: the cancel requests queued before it, if any, which the engine discards.Each bar, late bar and turn is answered by one batch: the cancel requests
ctx.Cancelqueued since the previous batch, each sent once and in queue order, then the ordersOnBarorOnLifecycleTurnreturned, each stamped with its label’s next attempt, then thecommitline. A late bar is buffered without a decision, and its batch carries the queued cancel requests alone; a strategy without aTurnHandleranswers a turn with its queued cancel requests and no order.The working view moves as on pb (The working view under lifetime v2), whichever handlers the strategy implements: an
updateorcancel_responseline moves it beforeOnOrderUpdateorOnCancelResponseruns, afillline folds the position and moves it beforeOnFill, and acancelledline retires the attempt beforeOnCancel. A confirmed cancel, a full fill and a venue expiry each clear the attempt, so v1’s stranded filled order (v1’s limits) does not occur on v2.corpaction,roll,session_start,session_endandshutdownare handled as on v1, the corporate-action mirror included.The runner accepts
roll-rebasewhenever theinitline offers it, as on pb (GLE-1505), and reads arebaseline with its bar lines whole (wire.ReadRebaseCSV2). It then applies the notice exactly as the pb runner applies aRebaseNotice(runner.applyRebaseNotice, one code path for both wires): the position’s cost, the working view and the trade anchors are restated, aligned views rebuilt, the series’ buffer replaced, andOnRebaseruns. It writes nothing. A block it cannot read whole (another line inside it, a bar line that does not parse, a bad COUNT) iserror,protocol_error,...naming the rebase, andOnRebasedoes not run. The same Go strategy sees the same rebase on either wire, bit for bit (engine/gle1505_csv2_rebase_e2e_test.go).An order’s name (Naming orders) goes out as its line’s NAME, and a
fillline’s NAME becomes the fill’sName.A batch the codec cannot write (an attached order, an OCO group, an MOC, more command lines than the limit) is refused whole with
error,csv_unsupported,..., and nothing of it is written. An order without a time in force is refused ahead of it, by name:Runreturnsalgolang: order "entry" (MSFT) has no time in force: stdio-csv-v2 needs an explicit TIF on every order; set Order.TIF to Day, GTC, IOC or FOK, or build the order with a constructor (MarketBuy, LimitBuy, StopBuy, StopLimitBuy, TrailingStopBuy or their Sell forms), which sets Dayand the
error,csv_unsupported,...line carries the same text, its commas written;. The constructors setDay, so the refusal meets an order built as a struct literal, or one whose TIF was cleared.A queued timer command (
ctx.ArmTimer,ctx.ArmSessionTimer,ctx.CancelTimer) has no line: the next batch of any kind, a warm-up block’s included, is refused whole witherror,csv_unsupported,..., naming the first queued command, before anything of it is written (Scheduled decision points).An
OnBarorOnLifecycleTurnerror iserror,strategy_error,...; v1’snoop,afillandcancellines, a secondinitand an unknown verb areerror,protocol_error,...; end of input without ashutdownline, inside a block or not, isalgolang: engine closed the stream without shutdown.
The Python lifecycle fixture
strategies/demo/python/lifecycle.py is the grammar’s non-Go fixture: stdlib-only Python that speaks stdio-csv-v2 raw, as smacross.py speaks v1. It submits one limit order (label entry, attempt 1, a GTC buy one below the last close), observes it working, cancels it (request id entry/1/c1), replaces it once with attempt 2, and leaves the replacement to fill. Its Mode input chooses how the replacement goes out:
wait(the default): the batch carries the cancel alone, and the replacement goes out at the first decision after the cancelled attempt has ended (a confirmedcancel_responseor itscancelledline); inlifecycle_wait.txtthat is the lifecycle turn the confirmed cancel grants.batch: one batch carries the cancel and the same-side replacement, and the engine’s race guard holds the replacement until the cancelled attempt has ended (lifecycle_batch.txt).
The fixture reads the batch limit from the init line and honours it: under a limit of 1, batch mode cannot fit both commands, so it sends the cancel alone and the replacement at the next decision, as wait mode does. It also shows the refusals a port should make: an init that does not offer lifetime-v2 (error,capability_unsupported,...), and a bad batch limit, a line other than bar or abar inside a warm-up block or a verb outside the v2 grammar (error,protocol_error,...).
make test runs python3 strategies/demo/python/lifecycle_test.py beside the smacross test. It replays both session transcripts through the strategy, feeding each engine line and comparing the replies with the transcript’s strategy lines byte for byte; replays batch mode under limits of 1 and 2 and wait mode under 1; checks its escaping against every v2 line of the catalogue (lines.txt); and checks the warm-up rule and the refusals. The Go tests parse and format the same transcripts, every line of which is canonical, so the two implementations agree on every line, and internal/wire’s TestTcrPythonFixtureHonoursBatchLimitOne runs the fixture as a process and reads each of its batches back with wire.ReadCSV2Batch at limit 1 (skipped when python3 is missing). The shared conformance suite’s Replay runs the fixture as a process over the same two transcripts from Go as well (strategies/conform, TestCf21ReplayPythonLifecycleFixture), feeding the engine lines and comparing every reply byte for byte, so the Python test and the Go test agree on every line; see Conformance under both lifetimes.
The fixture also runs against a live engine in make test: engine’s TestTch2PythonFixtureRoundTrip spawns it through the engine’s strategy host (skipped when python3 is missing). Wait mode runs on the simulator: the confirmed cancel grants the turn that submits attempt 2, and attempt 2 fills. Batch mode runs on the scripted venue, which leaves the cancellation pending: the race guard holds attempt 2 (held), releases it (working) once attempt 1 has ended, and attempt 2 reaches the venue once and fills. A byte-exact golden, engine/testdata/csv2/scripted_session.golden, pins a whole v2 session on the scripted venue, from init to shutdown: a warm-up block, a cancel and a same-side replacement in one batch, the replacement held, the turn, the release and the fill. Its strategy is an in-process scripted peer rather than the fixture, and go test ./engine -run TestTch2GoldenScriptedSession -update records it again.