Claude
Skills
Sign in
Back

kalshi

Included with Lifetime
$97 forever

Kalshi is a regulated prediction market exchange. Use this skill to interact with the Kalshi API for market data, trading, portfolio management, WebSocket streaming, and historical data retrieval.

Backend & APIs

What this skill does


# Kalshi API

[Kalshi](https://kalshi.com) is a CFTC-regulated prediction market exchange where users trade on the outcomes of real-world events.

Check this skill and the [official documentation](https://docs.kalshi.com) _FREQUENTLY_. The canonical machine-readable index of all docs lives at:

> **<https://docs.kalshi.com/llms.txt>**

Always consult `llms.txt` to discover every available page before building. It is the single source of truth for endpoint references, SDK docs, WebSocket channels, FIX protocol details, and getting-started guides.

---

## Key Concepts (Glossary)

| Term | Definition |
|---|---|
| **Market** | A single binary outcome contract (Yes / No) with prices in cents (1–99¢). |
| **Event** | A collection of related markets representing a real-world occurrence (e.g., an election, a weather reading). |
| **Series** | A template for recurring events that share the same structure and rules (e.g., "Daily Highest Temp in NYC"). |
| **Orderbook** | Bids only — in binary markets a YES bid at X¢ is equivalent to a NO ask at (100−X)¢. |
| **Fill** | A matched trade on one of your orders. |
| **Settlement** | The final resolution of a market (Yes or No) after determination. |
| **Multivariate Event** | A combo event created dynamically from a multivariate event collection. |

Full glossary: <https://docs.kalshi.com/getting_started/terms.md>

---

## Base URLs

| Environment | REST API | WebSocket |
|---|---|---|
| **Production** | `https://api.elections.kalshi.com/trade-api/v2` | `wss://api.elections.kalshi.com/trade-api/ws/v2` |
| **Demo** | `https://demo-api.kalshi.co/trade-api/v2` | `wss://demo-api.kalshi.co/trade-api/ws/v2` |

> **Note:** Despite the `elections` subdomain, the production URL serves ALL Kalshi markets — economics, weather, tech, entertainment, etc.

Demo environment info: <https://docs.kalshi.com/getting_started/demo_env.md>

---

## Documentation & References

All detailed examples, request/response schemas, and walkthroughs live in the official docs. Always consult these before building:

| Resource | URL |
|---|---|
| **Full documentation index (llms.txt)** | <https://docs.kalshi.com/llms.txt> |
| Introduction | <https://docs.kalshi.com/welcome/index.md> |
| Making your first request | <https://docs.kalshi.com/getting_started/making_your_first_request.md> |
| Quick Start: Market Data | <https://docs.kalshi.com/getting_started/quick_start_market_data.md> |
| Quick Start: Authenticated Requests | <https://docs.kalshi.com/getting_started/quick_start_authenticated_requests.md> |
| Quick Start: Create Your First Order | <https://docs.kalshi.com/getting_started/quick_start_create_order.md> |
| Quick Start: WebSockets | <https://docs.kalshi.com/getting_started/quick_start_websockets.md> |
| API Keys guide | <https://docs.kalshi.com/getting_started/api_keys.md> |
| Rate Limits & Tiers | <https://docs.kalshi.com/getting_started/rate_limits.md> |
| Pagination | <https://docs.kalshi.com/getting_started/pagination.md> |
| Orderbook Responses | <https://docs.kalshi.com/getting_started/orderbook_responses.md> |
| Historical Data | <https://docs.kalshi.com/getting_started/historical_data.md> |
| Subpenny Pricing | <https://docs.kalshi.com/getting_started/subpenny_pricing.md> |
| Fixed-Point Contracts | <https://docs.kalshi.com/getting_started/fixed_point_contracts.md> |
| OpenAPI Spec (YAML) | <https://docs.kalshi.com/openapi.yaml> |
| API Changelog | <https://docs.kalshi.com/changelog/index.md> |
| Kalshi Platform | <https://kalshi.com> |
| Demo Platform | <https://demo.kalshi.co> |

---

## Authentication

Kalshi uses **RSA-PSS signed requests** (not Bearer tokens). Every authenticated request requires three headers:

| Header | Value |
|---|---|
| `KALSHI-ACCESS-KEY` | Your API Key ID |
| `KALSHI-ACCESS-TIMESTAMP` | Current Unix timestamp in **milliseconds** |
| `KALSHI-ACCESS-SIGNATURE` | Base64-encoded RSA-PSS signature of `{timestamp}{METHOD}{path}` |

**Important:** When signing, use the path **without** query parameters. For example, sign `/trade-api/v2/portfolio/orders` even if the request URL is `/trade-api/v2/portfolio/orders?limit=5`.

### Generating API Keys

1. Log in → Account Settings → API Keys section.
2. Click "Create New API Key" to generate an RSA key pair.
3. **Store the private key immediately** — it cannot be retrieved again.

Full guide: <https://docs.kalshi.com/getting_started/api_keys.md>

### Python Signing Example

```python
import base64, datetime, requests
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding

def load_private_key(file_path):
    with open(file_path, "rb") as f:
        return serialization.load_pem_private_key(f.read(), password=None)

def sign_pss(private_key, text: str) -> str:
    sig = private_key.sign(
        text.encode("utf-8"),
        padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.DIGEST_LENGTH),
        hashes.SHA256(),
    )
    return base64.b64encode(sig).decode("utf-8")

def kalshi_headers(key_id, private_key, method, path):
    ts = str(int(datetime.datetime.now().timestamp() * 1000))
    path_no_qs = path.split("?")[0]
    sig = sign_pss(private_key, ts + method + path_no_qs)
    return {
        "KALSHI-ACCESS-KEY": key_id,
        "KALSHI-ACCESS-SIGNATURE": sig,
        "KALSHI-ACCESS-TIMESTAMP": ts,
    }
```

### JavaScript Signing Example

```javascript
const crypto = require("crypto");
const fs = require("fs");

function signPss(privateKeyPem, text) {
  const sign = crypto.createSign("RSA-SHA256");
  sign.update(text);
  sign.end();
  return sign.sign({
    key: privateKeyPem,
    padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
    saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
  }).toString("base64");
}

function kalshiHeaders(keyId, privateKeyPem, method, path) {
  const ts = Date.now().toString();
  const pathNoQs = path.split("?")[0];
  const sig = signPss(privateKeyPem, ts + method + pathNoQs);
  return {
    "KALSHI-ACCESS-KEY": keyId,
    "KALSHI-ACCESS-SIGNATURE": sig,
    "KALSHI-ACCESS-TIMESTAMP": ts,
  };
}
```

---

## SDKs

Kalshi provides official SDKs. Prefer these for production integrations:

| SDK | Install | Docs |
|---|---|---|
| Python (sync) | `pip install kalshi_python_sync` | <https://docs.kalshi.com/sdks/python/quickstart.md> |
| Python (async) | `pip install kalshi_python_async` | <https://docs.kalshi.com/sdks/python/quickstart.md> |
| TypeScript | `npm install kalshi-typescript` | <https://docs.kalshi.com/sdks/typescript/quickstart.md> |

> The old `kalshi-python` package is **deprecated**. Migrate to `kalshi_python_sync` or `kalshi_python_async`.

SDK overview: <https://docs.kalshi.com/sdks/overview.md>

For production applications, consider generating your own client from the [OpenAPI spec](https://docs.kalshi.com/openapi.yaml).

---

## Rate Limits

| Tier | Read | Write |
|---|---|---|
| Basic | 20/s | 10/s |
| Advanced | 30/s | 30/s |
| Premier | 100/s | 100/s |
| Prime | 400/s | 400/s |

Write-limited endpoints: `CreateOrder`, `CancelOrder`, `AmendOrder`, `DecreaseOrder`, `BatchCreateOrders`, `BatchCancelOrders`. In batch APIs each item counts as 1 transaction (except `BatchCancelOrders` where each cancel = 0.2 transactions).

Full details: <https://docs.kalshi.com/getting_started/rate_limits.md>

---

## Pagination

The API uses **cursor-based pagination**. Responses include a `cursor` field; pass it as `?cursor={value}` on the next request. An empty/null cursor means no more pages. Default page size is 100 (max typically 1000).

Full guide: <https://docs.kalshi.com/getting_started/pagination.md>

---

## REST API Endpoints Overview

Below is a summary organized by domain. For full request/response schemas, see the linked docs or browse <https://docs.kalshi.com/llms.txt>.

### Markets

| Endpoint | Method | Auth | Description |
|---|---|---|---|
| `/markets` | GET | No | List markets with filters (status, series, timestamp
Files: 2
Size: 36.5 KB
Complexity: 40/100
Category: Backend & APIs

Related in Backend & APIs