Interactive Brokers
How the fund talks to IBKR, what it refuses to do, and how to set it up. The decision record is decisions/0016-ibkr.md (the paper rehearsal and the contract map, decisions/0021); the research behind it is research/ibkr.md.
The fund reaches IBKR only through IBKR's Client Portal Gateway, which you run and log in to yourself. The fund never sees, asks for or stores your IBKR password. The settings store refuses any field named like one. You sign every order and you sign the go-live. Nothing in this document changes that.
Setting it up
Run the gateway. The server installer (
curl -fsSL https://resolution-9jj.pages.dev/install.sh | sudo sh, see operating) runs it as a container next to the fund and pins the download's checksum. By hand, the same is:# .env BROKER=ibkr COMPOSE_PROFILES=ibkr IBKR_GATEWAY_URL=https://ibkr-gateway:5000/v1/api IBKR_GATEWAY_SHA256=<the sha256 of clientportal.gw.zip>then
docker compose up -d --build. Or run it on the host: download IBKR's Client Portal Gateway, runbin/run.sh root/conf.yaml, and setIBKR_GATEWAY_URLto it (https://host.docker.internal:5000/v1/apifrom the container). The container's port is published on127.0.0.1only, and on a private network shared with the app. The gateway's ownconf.yaml(indeploy/ibkr-gateway/) admits only loopback and that network. The build refuses a download whose checksum differs from the pin; IBKR publishes no checksum of its own, so the pin proves only that every build uses the file that was checked once.Log in. The gateway's login page is
https://localhost:5000on the machine that runs it. On a server the port is published on loopback only, so you reach it through an SSH tunnel from a laptop, or over Tailscale:resolution servepublishes it on your tailnet ashttps://<server>.<tailnet>.ts.net:5001and setsIBKR_LOGIN_URLto that address. SetIBKR_LOGIN_URLto the address your browser reaches (Connections, broker card, "Gateway login page"); the Log in to IBKR button on the broker card and on Today then opens it in a new tab. WithoutIBKR_LOGIN_URLthe button falls back to the gateway's own origin, which is right only on the machine the gateway runs on, and the card says so beside the button. You log in on IBKR's page with your username, password and second factor; the fund only polls the session, and the card turns to "Logged in" by itself.Run the wizard. Go to Connections, open the broker card and choose "Test all steps". Each step is a real call:
Step What it checks The gateway answers The address is right, and the certificate is the one you trusted by its fingerprint (the step shows it and offers to trust it on first use; see operating) You are logged in The session is open (the fund revives one the gateway still holds, at most once every 5 minutes) The account Which account, IBKR's paper flag (a DUaccount is paper), base currency (EUR only for now)Every name maps to one contract ISIN first, on the home exchange, with the currency checked; ambiguous or wrong-currency matches are refused Live prices on each exchange One price per exchange; field 6509 shows whether this login has live, delayed or no market data An order preview IBKR's what-if for one share of the benchmark. Nothing is placed The daily statement check The read-only Flex statement compared with the fund's fills (see below) A paper round trip On demand, not part of "Test all steps", paper login only: one limit order for one share of the benchmark at half IBKR's price, placed, confirmed, cancelled, and the cancel confirmed (see below) Rehearse on paper, then go live: the checklist below. The paper flag is part of the terms you sign, so a go-live signed on a paper login says so.
Rehearse on paper, then go live
About twenty minutes from a running gateway to signed go-live terms, on a paper login first. Each item names what the app shows once it is done; do them in this order, because the readiness card and the ladder check the same things.
| What you do | What the app shows when it is done | About | |
|---|---|---|---|
| 1 | Start the gateway: docker compose --profile ibkr up -d beside the fund, or bin/run.sh root/conf.yaml on a laptop. | Broker card, first stage: Gateway reachable. The topbar badge IBKR: gateway down goes. | 2 min |
| 2 | On the broker card, leave Interactive Brokers selected (it is preselected), enter the gateway address, your paper account id (DU1234567 in shape) and the login page as your browser reaches it (IBKR_LOGIN_URL). Save. | The three fields read as set. The note beside the login button about the gateway's own address goes once IBKR_LOGIN_URL is set. | 2 min |
| 3 | Press Log in to IBKR and log in on IBKR's page with your paper-trading username and second factor. | Within a minute the card reads Logged in, Logged in as DU… (paper) and Session open; the Today banner "IBKR needs your login" goes. | 3 min |
| 4 | Press Test all steps. | Every step passes: the gateway answers, you are logged in, the account, every name maps to one contract, live prices on each exchange, an order preview, the daily statement check (with a Flex token; without one the step says so). A failed step says what to fix. | 3 min |
| 5 | Press Place and cancel under "A paper round trip". | "IBKR accepted order <id> (buy 1 <benchmark> at <limit>, price <price>) and confirmed its cancel. The round trip is closed." The Record gains a broker.rehearsal event; Governance's ladder shows "Paper rehearsal at the broker", marked for information. | 1 min |
| 6 | Open "From paper to live", step 1, Readiness. | Paper rehearsal at the broker reads "A paper rehearsal on DU… placed one order at IBKR and cancelled it on <date>". Every required item passes. | 2 min |
| 7 | Step 2, the dry run. | "Dry run" passes: one preview order, never placed. | 2 min |
| 8 | Step 3, read the terms and sign. | The broker card reads live on the paper account. The terms carry the paper flag and the contract id of every name; from here the fund sends the orders you sign to the paper account. | 3 min |
| 9 | For real money, later: go back to paper, log the gateway in with your live username, and do items 3 to 8 again. | The rehearsal is refused on that login, in the wizard's words: "Account U… is a real-money account. The rehearsal runs on a paper login only; nothing was sent." The terms you sign then carry the live flag. | — |
What the rehearsal is, exactly. The wizard reads IBKR's price for the benchmark, places one limit buy for one share
at half that price (day order, so it cannot fill), confirms only the prompts a fund order would confirm (o163, the
limit is away from the market, and o403), cancels it, and looks up to eight times for IBKR's Cancelled. It goes
to IBKR directly, never through the kernel: no proposal, no approval, no order in the fund's book. Its outcome is a
broker.rehearsal event (cancelled, cancel_pending, refused, rejected, filled, unknown) with IBKR's
order id and IBKR's own words, and it is refused before anything is sent when the fund is live (there is nothing
to rehearse: every order is the fund's) or when the login is not paper (IBKR's paper flag, or a DU account). A
filled outcome, which the price makes very unlikely, leaves one share in the paper account for you to sell there;
the fund does not book it. The rehearsal is recommended on the readiness card and shown on the ladder, never
required: a go-live without one is still yours to sign.
The session
A supervisor runs every 55 seconds whenever IBKR is configured, on paper as well as live. It tickles the gateway so an idle session stays open. It revives a brokerage session the gateway can revive, and re-primes the portfolio endpoints after every new session. It reduces all of that to one state, which the topbar badge, the broker card and Operations all read:
| State | Meaning | What you do |
|---|---|---|
authenticated | Logged in | Nothing |
needs_login | The gateway runs, the session is closed (IBKR closes it at least daily) | Log in again |
competing | IBKR Mobile or the website took the session | Log in again, or give the fund its own username |
starting | IBKR is opening the session or is in maintenance | Wait |
down | The gateway does not answer, or its certificate is not the one you trusted | Start the gateway, or run the wizard's first step |
The broker card shows the same state as four stages: the gateway (reachable or not), the login (logged in, logged
out, session taken, starting), the account ("Logged in as DU1234567 (paper)" or "(live)"), and the session's life
("Session open", or "Session expiring <when>" once IBKR's ssoExpires puts the login's end within the hour; IBKR
ends every login after about a day, whatever the tickle). While the session is anything but logged in, the browser
asks the server every 15 seconds and the card, the badge and Today change by themselves when you have logged in.
The topbar shows a badge only when something needs you. When the session needs a login, or IBKR Mobile or the website
took it, a notice with the login link also goes to your notification channels (kind broker_login), with the same
words as the banner on Today: "IBKR needs your login. Nothing is sent to IBKR until you log in." It is sent once per
episode, and an episode ends only when the session is authenticated again: a gateway container that restarts goes
down and comes back without a login, and that is one episode, told once, however many minutes it lasts, not once a
minute. A gateway that presents a certificate other than the trusted one is notified as broker_tls. A new login, by
you or revived by the gateway, primes the portfolio endpoints again and re-reads the paper flag before anything else
runs.
Orders: what the fund guarantees
Saved before sent. Every order is written as
sendingbefore the first byte leaves. If the process dies, the order is still known.A lost answer is
unknown, never "not sent". A timeout or a dropped connection after the order was written leaves itunknown. The fund then looks it up at IBKR by the client order id it sent (cOID). IBKR's first answer to a forced order list is empty by design, so the fund asks again. IBKR refuses a duplicatecOID, which guards the rare resend. An order that stayssendingorunknownpastORDER_STUCK_MIN(default 30 minutes) is flagged for you and never resent automatically: see operating.md.Only harmless prompts are confirmed. IBKR asks questions before accepting some orders. The fund confirms only the two the signed order already answers (
o163, the limit is away from the last price, which the fund's collar has checked;o403, the order will fill at once, which a marketable limit is meant to). Every other prompt stops the order and shows IBKR's words: an unknown id, a missing id, and any KID/PRIIPs text.No order on a stale price. A halted contract, a price that is only the previous close, or a login without live market data (6509
N,O,Z,Y) refuses the order. A 15-minute delayed price (D) is allowed and noted on the order.The preview is signed. When the fund is live, each order you are asked to sign carries IBKR's what-if with its time and hash: commission, initial and maintenance margin change, equity-with-loan change, order value with and without commission, the order's currency, the fund's euro rate for it, and warnings. The digest you sign covers it. A preview IBKR blocks cannot be signed.
The preview is checked when you sign and again before sending. When you sign, IBKR previews the order again. The signature is refused, nothing is sent, and the approval is issued again with IBKR's new preview (a new hash, so you sign again) when:
- the commission moved by more than the larger of EUR 1 (converted at the fund's rate for the commission's currency; without a rate only the 20% applies) and 20% of the signed commission, up or down;
- the commission appeared, vanished, or is in another currency;
- IBKR shows a warning you did not see (whitespace and case are ignored), or an error, or blocks the order.
If IBKR cannot be reached for that preview, the signature is refused and the approval stays open. The venue repeats the same comparison just before the order leaves (a resend after a crash included) and rejects the order unsent on a drift. An approval drafted without a preview keeps the older rule: the what-if runs just before sending, and what IBKR refuses is refused.
EUR only, for now. The cash check reads IBKR's ledger per currency. A live order in any other currency is refused: the fund refuses to sign it (it holds no cash in that currency, see Cash per currency), and the venue refuses to send it.
Pacing. At most 8 requests a second, under IBKR's 10, with IBKR's per-endpoint gaps (orders and trades 5 s). On a
429a read waits for IBKR'sRetry-After(a second when it gives none) and is tried once more; an order is never retried. A second429in a row, or aRetry-Afterover 30 seconds, pauses every call, orders included, for IBKR's 10-minute penalty box or theRetry-After, whichever is longer. Nothing is sent during the pause.No false alarms. A position difference counts only when it persists across two reads at least two minutes apart, and names with a pending corporate action are left out until you record it.
Paper fee models
Paper fills cost what PAPER_FEE_MODEL says (Settings, broker card). The kernel's fee estimate, and so its cash
check, uses the same model.
| Model | US stocks (USD) | European exchanges (EUR) |
|---|---|---|
flat (default) | The fund's own schedule: 10, 6 or 4 basis points by order size, at least 1.50 in the order's currency. No conversion fee. | Same |
ibkr_fixed | USD 0.005 a share, at least USD 1.00, at most 1% of the trade value. Exchange and regulatory fees included. | 0.05% of the trade value, at least EUR 3.00, at most EUR 29.00. |
ibkr_tiered | USD 0.0035 a share, at least USD 0.35, at most 1%, plus exchange and clearing fees. | 0.05%, at least EUR 1.25, at most EUR 29.00, plus exchange and clearing fees. |
Under both IBKR models, a trade in any currency but the euro also pays IBKR's currency conversion commission: 0.2 basis
points of the converted value, at least USD 2.00. It is recorded on the fill as fx_fee_eur, apart from the
commission, and the cost breakdown shows it in the conversion column. Without a euro rate for the currency it is left
empty and the breakdown says so.
Simplifications, on purpose:
- Tiered is priced at its lowest volume tier (up to 300,000 US shares or EUR 50 million a month).
- Tiered exchange and clearing fees are one figure: in the US USD 0.003 a share for taking liquidity plus USD 0.0002 clearing; in Europe 0.01% of the trade value. Real fees depend on the venue, the order type and whether the order adds or takes liquidity. US regulatory fees on sales (SEC and FINRA) are left out.
- Listings in other European currencies (GBP, CHF, DKK) use the euro figures, converted at the fund's rate.
The figures are IBKR's published schedules (stocks, currency conversion) as read on 2026-09-27. They are a reference to check against those pages before you rely on them; IBKR changes them. These models price paper fills only; a live fill is booked as IBKR reports it.
Flex reconciliation
With IBKR_FLEX_TOKEN (a read-only Flex Web Service token) and IBKR_FLEX_QUERY_ID set, the daily Flex pull also lays
IBKR's executions beside the fund's fills (the flex-recon:<statement date> job; the schedule is in
operating.md). It matches by execution id first, then by client order id, and reports:
- a fill whose quantity or price differs (both numbers shown)
- an execution at IBKR the fund has not booked, and a fill the fund booked that the statement lacks
- a trade the fund did not place
- a corporate action (flagged only)
Each difference is recorded once as a discontinuity, which you explain on the Risk page. The book is never changed to match, and a corporate action is never applied on the fund's own authority. The wizard's last step runs the same check on demand.
Cash per currency
The book holds cash per currency (decision 0018). Euro cash is the default; cash in another currency comes only from a conversion you signed.
- A conversion is a ticket you sign. On the Approvals page, ask for one (sell euros for a currency, or a currency
back into euros). The ticket shows the amount sold, the amount bought at the current rate, the estimated conversion
commission (none under the
flatfee model; IBKR's 0.2 basis points, at least USD 2, under the IBKR models) and when it expires (15 minutes). You sign its hash with the same key as an order. At signing, the fund checks the kill switch and its cash again; if the rate has moved more than 0.5%, nothing is converted, a new ticket is issued and you sign again. - No margin, per currency. Once the fund holds any currency cash, a buy is signed only if the cash it is paid from covers the order at its limit plus the fee estimate, less what orders already signed and not yet filled will take. A buy in a currency the fund holds is paid from that currency; one in a currency it does not hold is paid from euros on paper (converted at the fill's rate, as before). Live, a buy in any currency but the euro is refused unless the fund holds that currency. The refusal says which conversion to sign.
- Valuation. Each currency is valued in euros at the last rate recorded for it (from a fill or a conversion). A rate older than 72 hours is flagged as stale on the page. The difference from the booked euros is shown as currency gain or loss; it is realised when the cash pays for a buy or is converted back.
- Reconciliation. Live, each reconciliation also reads IBKR's ledger per currency. A currency where IBKR holds less cash than the fund's book, or less than zero, is recorded as a cash break and shown on the Approvals page. It does not raise a halt: IBKR's ledger is checked again before each order is sent, and an order it cannot pay for is refused.
- A book that never converts is unchanged. No currency accounts, the same cash figure, and no new refusal on paper.
Not built: sending a conversion to IBKR. A live conversion ticket is refused. To trade in another currency live you would convert in IBKR yourself; the fund does not yet book such a conversion, so a live buy in that currency stays refused.
The contract map
The wizard's contracts step resolves each name in the universe to one IBKR contract id (conid). The map is kept in
the Record as a broker.contracts event, written when it first resolves and again only when an id changes, and
reloaded when the fund starts: a restart costs no searches, and a gateway that is down at start does not empty it. It
lives in the Record rather than in a file in the data directory because the go-live terms you sign carry those ids,
and what you signed against belongs in the same chain as the signature; a file would be lost on a restore and
invisible to the audit. (The comment on broker_contracts in src/firm/projection.ts makes the same argument.)
Live, the map is compared with the signed terms, by the contracts step, by POST /api/broker/contracts, and by the
venue before every order. A conid that changed for a signed name is refused in exactly these words:
<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 refusal stands across restarts, because the Record says what moved. The other signed names are unaffected. The
broker panel lists the moved names under "Signed contracts changed at IBKR", /api/live carries them as drift, and
the wizard's contracts step fails with the same words. A map resolved before the signature never counts as drift: the
signed terms are the reference, and they are never replaced by a later map.
Not done yet
- Sending a currency conversion to IBKR, and with it live trading in currencies other than EUR. Paper conversions, cash per currency and the per-currency no-margin check are built (Cash per currency). A live conversion ticket and a live order in another currency are still refused.
- Nothing on this page has been run against IBKR's own systems, paper or live. The session supervisor, the wizard, the paper round trip, the contract map and the order path are tested against a fake gateway that answers with the shapes IBKR documents. The first run against a real paper account is yours, and the checklist above is written for it; read what each step says rather than assuming it.
- A login proxy served by the fund itself. You log in on the gateway's own page;
IBKR_LOGIN_URLtells the buttons where that page is for you.