# 0006. A broker is "supported" only when its conformance suite passes - **Status:** Accepted - **Date:** 2026-11-29 - **Deciders:** project owner ## Context Broker integrations are where trading systems quietly break. Every broker differs in authentication, symbol format, order payload validation, rate limits, partial-fill behaviour, rejection codes, GTT support, and what its websocket actually delivers versus what it documents. OpenAlgo's own docs are explicit that "broker presence does not guarantee every exchange, history, streaming or order feature" across its 39 plugins. Two of the target brokers have specific hazards: - **IBKR** requires a TWS or IB Gateway process, daily session resets, and 2FA. The adapter must treat re-authentication as a normal state, not an exception, and the deployment needs a gateway sidecar container. - **Indian brokers** differ on IP-change effect timing (Zerodha applies at next login, others immediately), and Fyers permits exactly one trading app per user. LEAN's answer to this is the right one: a `BrokerageTests` base class that every brokerage implementation must satisfy before it is considered complete. ## Decision Shipping an adapter is defined as **passing a conformance suite**, not writing code. `tests/conformance/broker/` is a parameterised suite run against every adapter (with recorded fixtures in CI, and optionally against a sandbox account). Mandatory cases: | Area | Required behaviours | |---|---| | Auth | token issue, expiry, refresh, daily re-auth, invalid credentials produce a typed error | | IP rejection | a distinct, non-retryable error when the request originates off-whitelist | | Symbol mapping | broker ticker ⇄ internal instrument, round-trip, ambiguous and delisted cases | | Orders | market, limit, stop, modify, cancel; validation errors surfaced as typed results | | Partial fills | one order, multiple fills, correct weighted average and remaining quantity | | Rejects | insufficient funds, frozen quantity, circuit limits — each mapped to a typed reason | | Idempotency | duplicate submit of the same `client_order_id` does not duplicate exposure | | Disconnects | websocket drop mid-session: reconnect, re-subscribe, reconcile missed fills | | Rate limits | exceeding the budget yields backpressure, not silent drops | | Reconciliation | reported positions and cash match ledger or raise drift | | Clock skew | broker timestamps outside tolerance are detected, not trusted | An adapter is registered in the plugin registry only if its suite is green in CI. A broker with a partially-implemented adapter may merge behind a `not_yet_supported` marker, but it must not appear in any user-facing broker list. ## Consequences **Easy:** adding brokers is a known-cost exercise with a definition of done; regressions are caught by the suite rather than by a user's money; adapter quality stops being vibes. **Hard:** the suite is the most expensive thing to build before the second adapter exists. It is also the reason the second adapter is cheap, so it is built alongside the first, not after. ## Alternatives rejected - **One integration at a time, tested by hand.** Scales to two brokers and fails at five. - **A thin generic HTTP wrapper over all brokers.** Every broker's semantics disappear into conditionals; this is what OpenAlgo's per-broker plugin directory exists to avoid. - **Deferring the suite until "we have users".** By then the first adapter has grown ad-hoc behaviour the suite would have forbidden.