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

# Kalshi WebSockets

> Real-time Kalshi market data with proxy-handled authentication

The proxy handles Kalshi WebSocket authentication (RSA-PSS) automatically using the credentials in `.env`. You connect to the proxy without needing to implement Kalshi's auth protocol yourself.

## Connect

```bash theme={null}
wscat -c "wss://gateway.graylayer.tech/ws/kalshi?api_key=your_key"
```

## Subscribe to channels

After connecting, send a subscribe command:

```json theme={null}
{"id": 1, "cmd": "subscribe", "params": {"channels": ["ticker"]}}
```

Available channels (see [Kalshi WebSocket docs](https://docs.kalshi.com/websockets/websocket-connection)):

* `ticker` — price and volume updates
* `orderbook_delta` — orderbook changes
* `trade` — trade events
* `fill` — fill events (requires authentication)

```json theme={null}
{"id": 2, "cmd": "subscribe", "params": {"channels": ["orderbook_delta"], "market_tickers": ["KXBTC-24NOV"]}}
```

## Troubleshooting

**401 Unauthorized?** Kalshi demo and production use different credentials. If your key is from [demo.kalshi.co](https://demo.kalshi.co), set:

```bash theme={null}
KALSHI_WS_URL=wss://demo-api.kalshi.co/trade-api/ws/v2
```

**Upstream:** `wss://api.elections.kalshi.com/trade-api/ws/v2`
