Stateful API Testing Tools Evaluated Against Kalshi-Class Order Book Complexity

Only a simulator that executes matching logic can test order books.

· 9 min read
Cover illustration for “Stateful API Testing Tools Evaluated Against Kalshi-Class Order Book Complexity”
Kalshi API Integration · November 12, 2026 · 9 min read · 1,955 words

Integration testing against stateful APIs requires an isolated simulator that executes business logic and preserves each call’s effects across the full workflow. For Kalshi-class order books, that means matching orders, updating positions and balances, and keeping REST responses consistent with sequenced WebSocket events. Static responses cannot show whether those dependencies work as they should, even when every endpoint passes its contract tests.

Why order book APIs are categorically harder to simulate than typical REST services

Kalshi’s exchange API combines REST for market data, orders, and portfolio, WebSocket for live order book updates, and FIX for institutional order entry. These are not independent surfaces when an order executes. A fill changes resting liquidity, position state, and available balance, and the live feed must report the change to the book. The dependencies cross both resources and transports. A simulator therefore has to reproduce more than valid responses to individual requests.

The WebSocket feed adds a strict ordering requirement. Kalshi’s documentation specifies an initial orderbook_snapshot, followed by incremental orderbook_delta messages with sequence numbers. If a delta is missed, the local book stays wrong until a fresh snapshot is requested. Kalshi changed RSA signing from RSA-SHA256/PKCS#1 v1.5 to RSA-PSS with MGF1(SHA256), then added Ed25519 as the recommended default, available from September 24, 2026. Its rate-limit model also moved from an RPS quota to a token bucket with seven independent tiers, making protocol drift another source of incorrect simulation.

What stateless mocks actually do when confronted with sequential, interdependent calls

Consider a test that submits a limit order and then reads the book. A stateless mock can acknowledge the submission, but its fixed book response will not include the resting order unless that response has been specifically scripted. The test then submits a crossing market order. Another predefined response can report a fill without processing any match. Subsequent position and balance reads still return their fixtures, rather than the position increase and balance debit that the fill should produce.

Scripting each expected response can conceal this break. The sequence may look correct while the mock has no mechanism connecting the reported fill to reduced resting liquidity. An order book makes that distinction especially consequential because fills can also trigger fills on other orders. The test can therefore pass against behavior the real exchange would reject. Adding more concurrent resting orders expands the number of dependencies that a response script must somehow represent.

Stripe’s charge-capture-refund lifecycle and PayPal’s retry model have the same broad limit, but their linear transitions do not capture how concurrent resting orders affect one another. A mock uses static or predefined responses to stand in for an interface. A stateful simulator instead maintains records and executes business logic in isolation. The practical division is stateless testing for isolated endpoint checks and stateful testing for multi-step workflows. Order book testing sits overwhelmingly in the second category.

What "stateful" actually requires at the simulator level for order book behavior to be correct

When a resting order is added, the next book read must show it, and when that order is cancelled, later reads must leave out its remaining quantity. Remembering that a request occurred is not enough. The simulator has to retain its effect on the exchange state so that later calls operate on the world earlier calls created.

Matching is the central transition to reproduce correctly. When an incoming order crosses resting liquidity, the simulator must match it, reduce resting quantities, update positions, adjust available balance, and emit the corresponding WebSocket deltas as one atomic state transition. Those effects cannot be independent fixtures. Otherwise, a test could observe a filled order while the book or portfolio still describes the state before the fill. Partial fills need the same consistency, with only the filled quantity treated as executed.

The event stream must preserve sequence integrity as well. Correct snapshots and deltas make it possible to test recovery after a connection drops, rather than merely test whether the client accepts messages. Realistic pre-seeded depth provides the conditions for walk-the-book logic, partial fills, and slippage scenarios. An empty book exercises little of that behavior. Configurable faults must then expose connection loss, tier-specific 429 responses, signing failures, and malformed delta sequences.

Continuous verification against the real API completes these requirements. Kalshi’s changes to signing, rate limiting, and REST/WebSocket authentication show why an implementation can become inaccurate even when its internal tests pass. Verification before each simulator release is the safeguard against that drift. Together, persistent state, atomic fills, sequenced events, useful depth, controlled faults, and ongoing verification establish the basis for evaluating the available approaches.

How Kalshi's own demo environment handles these requirements and where it stops

Kalshi’s demo environment is a separate exchange with mock funds, its own API hosts, and its own credentials. It is the appropriate starting point for authentication and basic order flow. Its purpose is narrower than controlled simulation. Kalshi warns that demo prices and market behavior may differ from real markets, so a successful run in the demo does not show how it will behave with a given liquidity profile.

Historical depth is another boundary of the public API. Kalshi’s /historical/* endpoints cover trades, candlesticks, markets, fills, orders, and positions, but not historical order book snapshots. Live depth is available through GET /markets/{ticker}/orderbook. That distinction prevents the demo alone from supplying the specific past book states needed for targeted depth and fill tests. Access to a functioning exchange is not the same as control over its starting state.

The demo also has no way to run controlled fault injection and sequence testing. A team cannot reliably make a WebSocket connection drop at a chosen point and then test the snapshot recovery path under conditions it has set. This is a difference in purpose. The demo supports basic integration with a separate exchange, while a simulator must let a test dictate both the state and the failure conditions.

What third-party historical order book data services add and where they still fall short

Third-party recorders fill in the missing history by polling live books on an ongoing basis and saving the full bid/ask depth. Their stored states give developers real resting liquidity for replay and backtesting. That closes a useful data gap. Instead of constructing every depth profile by hand, a developer can work from recorded market conditions.

Replay still does not execute a new order. A recorded book can show what liquidity existed, but it does not provide an interactive environment that accepts a test’s order, processes the resulting fill, and updates the test’s position state. The distinction is read-only history versus read-write behavior. Historical data can supply the starting conditions for a simulator, but it cannot replace the transition logic that integration tests need to exercise.

How to evaluate a stateful API testing tool against order book complexity specifically

A tool should be tested with five checks to start. The first is state continuity across a create-fill-cancel-position sequence, with assertions on the order response, book, positions, and balance. The second is transport consistency, including correctly sequenced snapshots and deltas. REST-only success is insufficient for this workload. Tests of the delta stream and reconnection path can catch failures that endpoint contract checks miss.

The third check is fault granularity. A generic error switch does not establish whether a tool can exhaust a particular rate-limit tier, disconnect at a chosen sequence number, or reject signing. The fourth check is fixture depth: the book must start with realistic resting liquidity so tests can cover partial fills and walk-the-book behavior. The fifth is drift control through continuous verification against Kalshi’s real API. A tool’s claim to support the API is weaker than evidence that its behavior is re-tested as the API changes.

These checks also need to hold under parallel execution. If concurrent CI jobs share mutable book state, one job’s fill can change the conditions another job is testing and create false positives. Each job needs isolated state. Within that boundary, however, REST and WebSocket must operate on the same book, rather than on separate sets of coordinated-looking responses.

Purpose-built simulators and general-purpose mocking frameworks meet these needs in different ways. The former are built around one API’s behavior, with continuous verification and updates as that API changes. General-purpose frameworks require the team to supply the relevant behavior and isolation configuration. That distinction does not remove the need for evaluation.

How fault injection and AI agent testing change what a Kalshi simulator must handle

Benchmarks that assume tools respond correctly and on time leave resilience to realistic tool faults untested. MCP-Injector found that agents completed far fewer tasks under a permanent-heavy stress profile, and larger models did not bring fault tolerance. Even with larger models, tests still need to check what happens when the tools an agent uses fail. For an order-management agent, those tools participate in a sequence whose later actions depend on earlier results.

AgentChaos found that silent failures were the most damaging category. Its research describes faults that return valid HTTP 200 responses while omitting information, allowing agents to continue without an explicit error. A wrong position state presents the corresponding risk in an order book workflow. The agent can continue making decisions from corrupted state without a visible rejection to stop it. Tests must therefore assert both the resulting exchange state and whether the agent completed its task.

Failures also need to compose within one scenario. A WebSocket connection can drop while a rate-limit bucket is exhausted and an agent is already partway through an order sequence. A simulator must let those failures happen at the same time while keeping their effects on the book and portfolio intact. Otherwise, the test covers recovery from individual errors but not recovery when one failure obstructs the response to another.

Tier-specific 429s test the rate-limit path for that tier, while drops at chosen sequence numbers test snapshot recovery from a gap whose place is known. Signing failures should trigger credential refresh and prevent silent retries. Partial fills must still lead to correct position updates when the agent expected a full fill. These scenarios extend the earlier evaluation criteria from protocol correctness to the agent’s behavior when its expectations no longer match exchange state.

How can integration tests run against stateful APIs without touching production?

CI pipelines that call live Kalshi endpoints can fail for reasons unrelated to the application change. Parallel jobs can exhaust rate limits, while demo downtime, signing key rotation, and network latency variance add other false negatives. Those failures weaken confidence in the test suite. The appropriate CI setup is an isolated, locally hosted simulator running in a container beside the application under test, without live credentials or exposure to the exchange’s rate limits.

Each parallel job should have its own simulator instance and book state. Purpose-built simulators provide this isolation by default, while teams must set it up by hand in general-purpose frameworks. REST requests and WebSocket subscriptions need to operate on the same state so that the test can assert the connection between a submitted order and the resulting book. A new subscription must receive the current snapshot, followed by correctly sequenced deltas for subsequent changes.

With that arrangement, failure scenarios become repeatable CI cases. The simulator can drop a connection mid-stream, exhaust a specific rate-limit tier, or inject a signing rejection without manipulating a live exchange. Deterministic starting depth also lets the suite assert partial fills and their portfolio effects across runs. When those tests run locally, they no longer depend on the external network. Continuous verification of simulator releases then addresses the separate question of whether the local behavior still matches Kalshi’s evolving API.

The decisive assertion is that every later read and event reflects what that order actually did, including when another operation or a controlled failure interrupts the workflow.

More in Kalshi API Integration