0021 · A paper rehearsal at the broker, and the contract map kept in the Record
Status: accepted, 2026-09-29. The code is src/broker/ibkr.ts (rehearse, pin, preload, contractDrift),
src/broker/ibkr/routes.ts (the wizard's contracts and rehearsal steps), src/firm/firm.ts (rehearseBroker,
keepContracts), src/firm/projection.ts (broker_rehearsal, broker_contracts) and src/record/schemas.ts.
Context
Interactive Brokers is the broker the product is built around, and the path to it had three gaps once the login was settled.
- Every wizard step was a read or IBKR's own preview. Nothing had ever exercised the order path against the gateway before the owner signed live terms, so the first order the fund placed was also the first test of placing one.
- The map from the fund's names to IBKR contract ids was cached in memory. A restart resolved it again, which cost searches, needed a logged-in gateway, and could silently produce a different id from the one signed into the go-live terms.
- On a server, the gateway's login page is on loopback and reached over a VPN; the fund's "log in" links pointed at the gateway's origin, which is right only on that machine.
Decision
- A paper rehearsal, never a fund order. On demand, on a paper login only, the wizard places one limit order
for one share of the benchmark at half IBKR's price, confirms only the prompts a fund order would (
o163,o403), cancels it, and waits for IBKR'sCancelled. It goes to the venue directly: no proposal, no kernel check, no approval, no row in the fund's order table. Its result is abroker.rehearsalevent carrying the venue, account, instrument, conid, client order id, IBKR's order id, the limit, the outcome and IBKR's words. It is refused before anything is sent on a live fund (every order in it is the fund's) and on a real-money login (IBKR's paper flag, or aDUaccount). On the readiness card and the ladder it is information, never a gate: a go-live without one is the owner's to sign. - The contract map is a Record event.
broker.contractsholds the mapping the wizard resolved, its failures and when it was checked. The projection reloads it at start, and the venue is preloaded from it so a restart costs no searches. It is written when it first resolves and again only when an id changes. It lives in the Record, not in a file in the data directory, because the go-live terms carry those ids: what the owner signed against belongs in the same hash chain as the signature, and a file would be lost on a restore and invisible to the audit. The projection marks a map resolved after the signature in force (after_live, by event order, since the sim clock can give two events one timestamp); only such a map is compared with the signed one. - A changed id for a signed name refuses the order in fixed words. Live, the venue compares the latest map
with the signed terms. A moved conid refuses every order for that name with "
<name>: IBKR's contract changed since you signed the go-live terms (conid <signed> is now <latest>). Nothing is sent for <name> until you go back to paper and sign the terms again." The wizard's contracts step fails with the same words,/api/livecarries the drift, and the broker panel shows it. The signed map is never replaced by a later one; the refusal is lifted only by going back to paper and signing again. This is a venue refusal on the order path, not a kernel rule: the kernel's rules are about the portfolio, and this is about the broker's identity for a name. - IBKR is the default on the broker form, and the login page is a setting.
BROKERshowsibkrpreselected and stores it only when the owner saves.IBKR_LOGIN_URLis a broker-card field, so the "Log in to IBKR" button opens the page the owner reaches; unset, the gateway's origin is used and the card says that address is right only on the gateway's machine. The session supervisor tells the owner once per episode, and an episode ends only when the session is authenticated again, so a gateway container that restarts is one notice, not one a minute.
Alternatives
- Rehearse through the kernel as a proposal. Rejected: it would put a rehearsal in the fund's book and its measurements, and a HARD rule (cooling-off, sizing) could refuse it for reasons that have nothing to do with the broker. The rehearsal tests the broker, not the fund.
- A market order, or a limit near the market, for the rehearsal. Rejected: a fill on a paper account is harmless but noisy, and the point is to prove placement and cancellation, not execution. Half the price with a day time-in-force cannot fill on any exchange the fund uses.
- Keep the map in
IBKR_CONIDSor a data-directory file. The setting stays for names the wizard cannot resolve. A file was rejected for the reason in the decision. - A kernel HARD rule for contract drift. Rejected: the kernel does not know brokers. The refusal sits where the id is used.
Consequences
- Two new event types,
broker.rehearsalandbroker.contracts, indocs/reference/events.md. - The wizard has a step that sends an order to IBKR, on paper. It is the only such step and it is not part of "Test all steps".
- None of this has been run against IBKR's systems; the tests use the fake gateway.
docs/ibkr.mdsays so.
Tests: test/ibkr-rehearsal.test.ts, test/ibkr-contracts.test.ts, test/setup-readiness.test.ts,
test/setup-config.test.ts.