> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kalshi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Binary FIX sessions

> Use Simple Binary Encoding for FIX market data and order entry in Predictions and Margin.

Binary FIX uses the [Kalshi FIX SBE v1 schema](https://docs.kalshi.com/fix/kalshi-fix-sbe-v1.xml) in **both directions**. Your client opens one TCP/TLS connection to the assigned SBE destination port and sends a binary Logon. The gateway returns the binary Logon acknowledgement on that same connection. Keep the socket open for requests, responses, unsolicited updates and session messages. Replies use the established socket. Your client only needs to open outbound connections.

## Connections and ports

Each enabled product has a dedicated SBE market-data listener and a dedicated SBE order-entry listener. The destination selects the encoding before Logon. Contact your institutional connectivity representative for the enabled hostname and port for each product, session type and network route.

| Session | Logical target | Client sends | Gateway sends on the same socket |
| - | - | - | - |
| Market data (MD) | `KalshiMD` | Book subscriptions and unsubscriptions | Snapshots, incremental book or trade updates, subscription responses |
| Nonpersistent order entry (NR) | `KalshiNR` | New, replace and cancel requests | Execution reports, fills and rejections |

To use market data and order entry together, open **two bidirectional connections per product**, each with its own authorized FIX key. Running both sessions on Predictions and Margin simultaneously uses four connections. The operating system normally selects the client source port. Each direction maintains its own FIX sequence on each connection.

For AWS PrivateLink or VPC peering, use the binary destination port assigned to that private route. Allow the outbound connection to that port and its return traffic. Keep the assigned Kalshi FIX hostname as the TLS server name even when dialing a private endpoint DNS name. Sign the binary Logon as described below. [FIX connectivity](https://docs.kalshi.com/fix/connectivity.md#private-connectivity)

## Framing

Each frame carries one session or application message. Read the six-byte framing header, validate its size, then read exactly the declared number of remaining bytes. Both client and gateway send binary frames from Logon onward. A frame is at most 2 MiB including its headers.

| Offset | Size | Encoding | Field |
| -: | -: | - | - |
| 0 | 4 | Big-endian uint32 | Total frame length, including the six-byte framing header |
| 4 | 2 | Big-endian uint16 | SBE encoding type, `0xeb50` |
| 6 | 2 | Little-endian uint16 | Fixed root block length |
| 8 | 2 | Little-endian uint16 | Template ID |
| 10 | 2 | Little-endian uint16 | Schema ID, `3` |
| 12 | 2 | Little-endian uint16 | Version, `1` |
| 14 | 4 | Little-endian uint32 | Sending session's sequence number |
| 18 | 8 | Little-endian int64 | UTC sending time in microseconds since the Unix epoch |
| 26 | variable | Schema-defined | Root fields, repeating groups and variable-length data |

Session sequences start at 1 in each direction. Reserve 2147483647 for orderly logout. Reconnect and reconcile outstanding requests before sequence exhaustion. Strings have a little-endian uint32 byte length and UTF-8 bytes. Follow the fixed block and repeating-group declarations in the published schema.

On a live connection, a gap triggers ResendRequest (template 9). For example,
if the gateway expects sequence 26 and receives 28, it requests 26 through 27
and retains 28. Supply the missing messages, or send a SequenceReset gap fill
(template 8) at 26 with next sequence 28 for messages you deliberately skipped.
The gateway can then process 28. It closes an unresolved gap after twice the
negotiated heartbeat, capped at 120 seconds. A client request to resend missed
outbound messages receives a gap fill on this nonpersistent stream. Reconcile
uncertain orders and refresh the book on reconnect.

For example, this Heartbeat frame has sequence 2 and test request ID `abc`:

```text theme={null}
00 00 00 21 eb 50 00 00 04 00 03 00 01 00 02 00 00 00 00 40 1e 18 24 0a 06 00 03 00 00 00 61 62 63
```

## Authentication

Select the profile assigned to the endpoint. The client principal is its canonical lowercase FIX API key UUID. Predictions and Margin share logical gateway names and have distinct signed profiles.

| Profile ID | Profile string | TargetCompID |
| -: | - | - |
| 1 | `kalshi.fix.sbe.predictions.md` | `KalshiMD` |
| 2 | `kalshi.fix.sbe.predictions.nr` | `KalshiNR` |
| 3 | `kalshi.fix.sbe.margin.md` | `KalshiMD` |
| 4 | `kalshi.fix.sbe.margin.nr` | `KalshiNR` |

Encode the eight-byte fixed Logon block first. The reset flag must be 1. The heartbeat interval must be at least three seconds. The two option masks distinguish an omitted boolean from an explicitly supplied false. Enable only options declared for the profile in the XML. NR prices use fixed dollar units. On NR, set both the presence and enabled masks for option bit 0 to request cancel-on-disconnect. Omit it or explicitly set false to let resting orders retain their normal lifetime.

Clients generate encoders and decoders from the public XML and negotiate this exact version. Keep a decoder for each supported version. Incompatible layouts receive a new version or profile and a member notice before their serving endpoints change.

Use sequence 1 and a sending time aligned to a whole millisecond. Join the following strings with one SOH byte (`0x01`) between fields and no trailing delimiter:

1. Profile string
2. Schema ID and version as **two** decimal strings
3. UTC sending time in `YYYYMMDD-HH:MM:SS.mmm` form
4. `A`
5. Decimal session sequence (`1`)
6. Canonical API key UUID
7. Logical TargetCompID
8. Lowercase SHA-256 hex digest of the exact eight option bytes

A Predictions MD Logon with a 30-second heartbeat and omitted option masks uses `01 01 1e 00 00 00 00 00` and digest `4139006b015253ecac5de8d3a330979fb38f76bf1733a65fbf739cb63599a37f`. Sign the resulting bytes with the registered Ed25519 key, or RSA-PSS with SHA-256. Send the base64 signature and both identities in template 1. Verify the profile and identities in template 2 before issuing application requests. A rejected Logon does not establish a session.

The downloadable Logon vectors include the exact signed bytes, public verification keys, signatures, and complete frames. One uses Ed25519 with omitted options and one uses RSA-PSS/SHA-256 with explicit option values. [Download the v1 Logon vectors](https://docs.kalshi.com/fix/kalshi-fix-sbe-logon-v1.json)

## Client examples

The Go and C++ initiators connect to the assigned MD TLS hostname, sign Logon with a local PEM file, verify the echoed profile, request a snapshot, and print its level count and best bid and offer. The output shows price in 1/10,000 USD and quantity in 1/100 contract. Both handle TestRequest and chunked snapshots. The examples accept Ed25519 or RSA-PSS credentials. [Go source](https://docs.kalshi.com/fix/examples/market-data.go.txt) · [C++ source](https://docs.kalshi.com/fix/examples/market-data.cpp)

Generate client codecs from the downloaded XML with Real Logic SBE 1.42.1 and Java 25. The build commands assume the downloaded examples and schema are in the current directory. The C++ example requires OpenSSL 3 or newer.

```bash theme={null}
for language in Golang Cpp; do
  java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED \
    -Dsbe.target.language="$language" -Dsbe.output.dir="generated/$language" \
    -jar sbe-all-1.42.1.jar kalshi-fix-sbe-v1.xml
done

mkdir -p go-client
cp -R generated/Golang/kalshi_fix_sbe go-client/
cp market-data.go.txt go-client/main.go
(cd go-client && go mod init example.com/fixmd && go build -o ../fixmd-go .)

c++ -std=c++17 -Igenerated/Cpp $(pkg-config --cflags openssl) market-data.cpp \
  $(pkg-config --libs openssl) -o fixmd-cpp
```

Run either binary with the TCP destination, port, canonical key ID, private-key file, symbol, and product (`predictions` or `margin`). By default the client sends the destination hostname as TLS SNI and verifies it against the certificate. When dialing a private endpoint DNS name or IP address, pass the assigned Kalshi service hostname as the optional last argument. Both clients use it for SNI and certificate verification. Set `KALSHI_FIX_CA_FILE` to a trusted CA bundle when your assigned test endpoint requires one.

```bash theme={null}
./fixmd-go "$FIX_HOST" "$FIX_PORT" "$FIX_KEY_ID" "$FIX_KEY_PEM" "$FIX_SYMBOL" predictions
./fixmd-cpp "$FIX_HOST" "$FIX_PORT" "$FIX_KEY_ID" "$FIX_KEY_PEM" "$FIX_SYMBOL" margin

# Private route with a distinct TLS hostname (supported by either client)
./fixmd-go "$PRIVATE_ENDPOINT_ADDRESS" "$FIX_PORT" "$FIX_KEY_ID" "$FIX_KEY_PEM" "$FIX_SYMBOL" predictions "$FIX_TLS_SERVER_NAME"
```

## Market data

Use template 100 to request a snapshot, subscribe to updates, or unsubscribe. The optional feed selects bids, offers and trades. Books use absolute resulting sizes. A deletion means the price level has been removed. Apply all entries in template 102 in order, including any prints. Private order identity and subaccount fields are included only in the recipient's authorized view. A trades-only subscription starts without a snapshot.

Use template 101 as a replacement snapshot for the subscribed sides. For a larger ladder, buffer template 106 chunks belonging to the same snapshot, symbol and connection. Validate chunk index, declared total chunks, total levels and cursor. Apply the assembled ladder only after the final expected chunk arrives; discard incomplete snapshots on disconnect. Predictions' optional MDExecID identifies an exchange position and can skip values. Margin omits it. Predictions supports security-status subscriptions through templates 104 and 105. [Market data semantics](https://docs.kalshi.com/fix/market-data.md)

## Order entry

| Request | Template | Primary responses |
| - | -: | - |
| New, cancel, replace | 200, 201, 202 | Execution report 210, cancel reject 211, session or business reject |
| Mass cancel | 203 | Mass-cancel report 212 and the affected orders' lifecycle reports |
| Order-group action | 204 | Order-group response 213 or reject |
| Authorized historical event replay | 205 | Reconstructed execution reports 210, completion 214 or refusal 215 |
| Margin unsolicited updates | — | Trading-session status 216 and corporate-action status 217 |

This binary profile covers ordinary order-book trading. For the optional settlement-report subscription (35=UMS) or accepting an RFQ quote by QuoteID, use the existing classic FIX sessions.

Predictions NR supports markets on the native Predictions shards. A request
for a Predictions market hosted on the Margin matcher is refused before order
placement with `UNSUPPORTED_FIX_ROUTE`. Margin NR uses the native Margin matcher.

Ordinary new orders are limit orders. New, cancel, replace and market-scoped mass-cancel requests may select a customer account or a subaccount. Supplying both selectors on those requests is rejected. A session-scoped mass cancel uses the authenticated session and ignores both selectors. Preserve an explicitly supplied subaccount zero for market-scoped cancellation. Prices are in ten-thousandths of a US dollar. Order and fill quantities use hundredths of a contract. The order-group contractsLimit field uses whole contracts. Mass-cancel scope and response are ASCII FIX codes: market scope is byte 0x31 and session scope is byte 0x36. The market determines allowed tick and quantity increments. Average price carries a whole-dollar part and a signed fractional part at scale 10. Fees and collateral values use their schema-specific units. A pending report acknowledges processing. Use the exchange-confirmed new, replaced, canceled, rejected or fill report to decide the actual outcome. [Order entry](https://docs.kalshi.com/fix/order-entry.md) · [Order groups](https://docs.kalshi.com/fix/order-groups.md)

New, replace, cancel and mass-cancel requests require a nonempty `clOrdId` for response correlation. A single cancel or replace also requires `origClOrdId` for the order being changed, including a replacement that supplies an exchange `orderId`. On Predictions, a supplied `maxExecutionCost` must be positive. Leave `execInst` empty or send the exact single instruction `6` for post-only or `E` for reduce-only, subject to the product and time-in-force rules. For a standard limit new order, the matching engine rejects a GTD deadline at or before its processing time, before matching against resting liquidity. Send `timeInForce='3'` for immediate-or-cancel execution. A GTD replacement requires a future deadline. Leave the replacement price null to keep the existing price. A supplied price, including zero, is subject to the market’s price rules.

Session-wide mass cancel uses the same shard fanout as classic FIX. A cancel can complete on some shards while another is unavailable, and a previously submitted order can still be in flight. If an orderly binary listener drain interrupts the request, the gateway stops sending it to further shards. After a disconnect without a confirmed mass-cancel report, reconcile surviving orders before retrying or resuming trading.

### Cancel-on-disconnect

The `KalshiNR` binary listener uses the same policy as classic NR on each product. When an opted-in connection closes, the gateway requests cancellation of resting orders in the existing scope of that FIX key and authenticated account. After a gateway process loss, FIX-data performs the same cleanup when its Redis lease expires. The lease lasts twice the negotiated heartbeat interval for a COD-enabled session. Other keys keep their own orders.

A definitive binary Logon rejection preserves earlier resting orders. If the connection closes before you receive LogonAck, the requested policy may already be active. Reconcile orders under that key before resuming trading.

Wait for the confirmed execution report when you need a definite outcome. A command in flight at disconnect can have an uncertain outcome. Reconcile it and any resting orders before resuming trading. An introducing broker using affiliate accounts should reconcile those orders under their economic owner, as with classic FIX.

Use a key provisioned for the nonpersistent NR endpoint. Before reusing a key from a persistent classic session, reconcile outstanding commands. `KalshiRT` uses its existing classic listener.

Both MD and NR reset their FIX sequence numbers to 1 on reconnect. Recover a book with a fresh snapshot and treat skipped prints explicitly. For an uncertain order outcome, use authorized execution-event replay or reconcile the account and order using its identifiers. Historical replay retains the existing entitlements and locked-key restrictions. An empty asynchronous state read does not establish that an order failed. Submit a new command only after resolving the previous outcome. [Drop-copy and historical-event rules](https://docs.kalshi.com/fix/drop-copy.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.