Mapping Kalshi Session Lifecycle States to Integration Test Checkpoints

Kalshi's eight market states each need an assertion, including silent transitions.

· 9 min read
Cover illustration for “Mapping Kalshi Session Lifecycle States to Integration Test Checkpoints”
Kalshi API Integration · November 26, 2026 · 9 min read · 1,944 words

Testing a stateful API requires a test environment that remembers earlier calls and applies transitions in the correct order. For Kalshi, integration tests need checkpoints for market states, order states, and how sessions behave. A stateful simulator provides repeatable coverage without production traffic, while a dedicated live-API stage covers the behaviors the simulator does not yet reproduce faithfully.

What the Kalshi market lifecycle actually consists of

Diagram: Kalshi Market Lifecycle: Eight Statuses and Their Transitions. Visualizes: Show the eight REST statuses of the Kalshi market lifecycle as a directed flow: initialized → active ↔ inactive → closed → determined → disputed → amended →…

Kalshi’s market lifecycle documentation defines eight REST statuses, namely initialized, active, inactive, closed, determined, disputed, amended, and finalized. An initialized market exists but has not opened for trading. An active market accepts trading, while an inactive market is temporarily paused by the exchange. Closed means the market has passed close_time and awaits determination. Finalized means settlement is complete and positions have been paid out.

In GET /markets?status=, unopened maps to initialized, open maps to active, and paused maps to inactive. The closed filter includes markets whose status is closed and all other markets past close_time that are not yet finalized. The settled filter maps to finalized. Four time fields govern lifecycle timing, including open_time, close_time, expected_expiration_time, and latest_expiration_time, and each can move independently.

Determination does not immediately release the settlement payment. After closure, the result is set to yes, no, or scalar, and a timer runs for settlement_timer_seconds. A challenge during that interval can move the market from determined to disputed. Re-determination moves it to amended and restarts the timer. The dispute branch ends at finalized once the settlement timer runs out.

How transitions actually fire — implicit, explicit, and edge-case sequences

The lifecycle documentation distinguishes time-driven transitions from event-driven transitions. When open_time passes, an initialized market becomes active without an activated WebSocket event. When close_time passes, an active or inactive market becomes closed without a WebSocket event. Silence is therefore part of the protocol. A client must poll REST or reason from time fields rather than wait for a notification that will never arrive.

Deactivation emits deactivated, while reactivation emits activated and cancels all resting orders. Determination emits determined, and finalization emits settled, even though the REST status is finalized. Reopening introduces an ordered pair of events. If close_time moves into the future, close_date_updated fires before activated, so a client that handles either event on its own misses the compound transition.

Kalshi’s WebSocket lifecycle documentation also separates subscription scope. The market_lifecycle_v2 channel covers markets other than MVE markets identified by KXMVE*, while multivariate_market_lifecycle covers only MVE markets. Messages contain type, sending_ts_ms, sid, seq, and a channel-dependent msg body. Sequence numbers support gap detection, but message bodies cannot be treated as interchangeable across channels.

The server sends an orderbook_snapshot containing full state before incremental orderbook_delta updates. A reconnecting client needs that snapshot-then-delta sequence to establish its current view, rather than merely resume processing deltas against an old book.

Order state and FIX session lifecycle as parallel checkpoint surfaces

Order state evolves independently of the market status. An order can move from resting through partially_filled to filled, with canceled and expired also serving as terminal states. The recommended tracking handle is client_order_id. These states intersect with market transitions because reactivation cancels resting orders, while closure rejects every order operation, including cancellations, with MARKET_INACTIVE. Resting orders are cancelled soon after closure, and updates about those cancellations go out on user channels.

The source marks this behavior as not yet live. That distinction belongs in version-aware coverage rather than an assumption that entry and position-closing requests always receive identical treatment.

Kalshi’s FIX documentation lists six session types, each with its own port. KalshiNR uses port 8228 without message persistence, while KalshiRT uses port 8230 with retransmission and continuity across maintenance windows. KalshiDC provides drop copy on 8229, and read-only KalshiPT provides post-trade settlement reports and position resolution on 8231. KalshiRFQ serves requests for quote on 8232, while KalshiMD serves market data on 8233.

During the Thursday 3:00–5:00 a.m. ET maintenance window, sessions can drop, with NR losing in-flight messages while RT retains continuity. On New Order Single, tag 21006, CancelOrderOnPause, set to Y cancels resting orders when a trading or exchange pause begins. Tests need to check how it behaves both when set and when unset, before an unscheduled pause reveals the difference.

Why each lifecycle state defines a natural integration test checkpoint

A lifecycle checkpoint is justified whenever state changes the API’s accepted operations or the client’s obligations. The test must assert that boundary. At initialized, the market should be queryable through GET /markets/{ticker}, have a future open_time, and reject orders. However, the lifecycle documentation allows a brief 404 immediately after a created event, so this checkpoint also includes retry with backoff.

At active, assertions cover accepted order placement, an available order book, live streams, and inclusion in the open filter. At inactive, they cover rejected placement, resting-order cancellation behavior, user-channel updates, and inclusion in paused. Reactivation requires a joint assertion. The client must handle both the activated event and cancellation of all resting orders, rather than treat trading availability as evidence that its previous orders remain live.

At closed, every order operation must get MARKET_INACTIVE, even a request to cancel an order. The checkpoint also covers subsequent resting-order cancellations, published updates, an unset result, and inclusion in the closed filter. At determined, the result is present and the timer is running, but positions remain unpaid. Dispute and amendment then test whether the client tolerates a revised result and a restarted timer. At finalized, assertions cover settlement_ts, paid positions, and inclusion in settled.

These assertions extend beyond the REST response itself. Silent opening must not leave the client waiting for activated, reopening must preserve event order, and reconnect must establish a fresh snapshot before deltas. The checkpoint is the agreement among market state, order state, and observed events.

What a stateless mock cannot reproduce in this map

Mocking each call works well for stateless happy-path tests. A canned response can check whether a client parses a market, recognizes a rejection code, or handles an individual event. Canned responses are insufficient when correctness depends on earlier actions, elapsed time, or several surfaces describing the same evolving object.

A stateless request-response mapping cannot use what happened earlier to work out a transition. Returning initialized once does not cause a later response to become active when open_time passes. Likewise, serving close_date_updated and activated fixtures can test handlers without proving that a time-field update triggers both events in order. A scripted sequence can supply predetermined outputs, but it does not establish that those outputs follow from the market’s current state.

The same gap affects orders and reconnect behavior. A hardcoded snapshot may omit orders placed during the test, while a cancellation fixture need not correspond to any resting order. Neither establishes that reactivation actually clears the relevant orders. The test can pass even though its individual responses describe incompatible worlds.

Transient and reversible states expose the distinction most clearly. The 404-after-created case requires queryability to change over time, while a dispute requires the result and settlement timer to change together. Mocks can script those examples separately. Once a harness remembers orders, tracks timers, and computes transitions, however, it has taken on the stateful behavior that the original per-call approach lacked.

What a stateful simulator does at each checkpoint that a mock cannot

Rystic is one option for teams that want a locally runnable Kalshi stand-in that remembers prior calls, supports seeded state, and lets tests check silent transitions and the ordered close_date_updated-then-activated reopening sequence. Its simulators run locally or in CI without live credentials or rate limits, with realistic pre-seeded data and fault injection for latency, 429s, and 503s.

The defining requirement is a shared state model. Adding an order, listing it, and cancelling it must operate on the same order. Seeded state also lets a test begin at initialized, active, or closed without traversing every earlier transition. That makes a particular boundary directly reachable while preserving the history created during the test itself.

Time passing or test-controlled time advancement should change market state without emitting events for implicit transitions. Reopening should produce the ordered event pair because the simulator applied the time-field change to a closed market. Tests of reactivation need to check that resting orders are cancelled and that the matching updates go out on user channels.

A coherent book also makes reconnect assertions meaningful. Its snapshot must reflect orders accumulated during the test before subsequent deltas arrive. Settlement coverage requires a result, a dispute, an amendment, and a restarted timer within the same evolving market. Where FIX behavior is modeled, NR loss and RT replay must remain distinct. These fidelity criteria require verification even for a tool described as stateful.

Fault injection mapped to lifecycle checkpoints

Fault coverage begins at the initialized market’s queryability boundary. Injecting the brief 404 after created tests whether retry with backoff bridges the lag without treating creation as a failed operation. At active trading, a 429 on placement exercises rate-limit handling, while a 503 on order-book fetch exercises recovery from unavailable data. Delayed WebSocket delivery tests timeout handling at that same checkpoint. Each fault belongs to a particular operation and state.

The active-to-inactive boundary needs an abrupt deactivated event. The assertion is that the client stops sending orders rather than continuing until ordinary placement attempts fail. Mass-cancel notifications then exercise updates to its tracked orders and positions. At the closed boundary, tests must check that cancellation attempts are rejected, because a client may assume it can still cancel orders after placement stops.

Settlement faults test assumptions about finality: a disputed transition after determination must prevent the client from treating the known result as completed settlement. For FIX NR, a simulated maintenance disconnect must demonstrate unrecoverable message loss on reconnect. The corresponding RT test needs the opposite persistence expectation. A generic “disconnect recovered” assertion cannot distinguish correct behavior for these sessions.

Disconnecting after deltas have accumulated tests whether reconnect replaces stale deltas with a fresh snapshot. Before initialization, on-request creation of weather, concert, and flight markets has another rate-limit boundary. The changelog specifies endpoint-specific 429 codes for per-account rolling limits, which client logic must distinguish from global-limit responses in the error details.

Keeping the simulator accurate as the Kalshi API evolves

A stateful simulator can still reproduce the wrong contract. With drift, ordinary market reads may still look right even when a rejection code or transition side effect no longer matches the live API. A test that checks only GET /markets/{ticker} will not detect an incorrect response at the MARKET_INACTIVE boundary. Statefulness solves continuity.

Verification therefore needs the same checkpoint map as integration testing. Comparing schemas alone cannot show how silent transitions work, what side effects cancellations have, which order events arrive in, or whether sessions persist. Before every simulator release, tests should compare how it and the live API behave at those boundaries. Nightly checks can then catch changes between releases before a client runs into the drift.

The platform’s published methodology describes verification against the real API before each release, with nightly checks to catch and repair drift. It also describes published fidelity scores and sharing failing tests with customers. Those results make the remaining uncertainty visible. An overall score is useful context, but a particular integration test needs a live environment if the simulator fails at the boundary it tests.

The practical workflow divides coverage by demonstrated fidelity. The simulator handles the bulk of repeatable lifecycle checkpoint tests in CI, including seeded states and controlled fault paths where its behavior matches. A dedicated live-API integration stage uses the live demo environment to test the transition behaviors and edge cases that the simulator is known to miss. The lifecycle map thus determines both what to assert and where that assertion can credibly run.

Sources

  1. API Changelog - API Documentation
  2. Market Lifecycle - API Documentation
  3. Market & Event Lifecycle - API Documentation

More in Kalshi API Integration