# Kalshi API — Markets, Order Book & Trades (`dirtycode/kalshi-api`) Actor

Live data from Kalshi, the CFTC-regulated US prediction market: market odds ranked by volume, full L2 order-book depth, and executed trades with volume-weighted average price. No login, no API key, no account required.

- **URL**: https://apify.com/dirtycode/kalshi-api.md
- **Developed by:** [Dirtycode](https://apify.com/dirtycode) (community)
- **Categories:** Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Kalshi API — Markets · Order Book · Trades

Live data from **Kalshi**, the CFTC-regulated US prediction market. Market odds ranked by
traded volume, full L2 order-book depth, and executed trades with a volume-weighted average
price. All public data — **no login, no API key, no account.**

### Three datasets, priced separately

| Mode | What you get | Price |
|---|---|---|
| `markets` | Live odds, ranked by traded volume | **$0.005** per market |
| `orderbook` | Every bid and ask level with size | **$0.02** per snapshot |
| `fills` | Executed trades with aggressor side | **$0.002** per trade |

You only pay for rows you actually receive.

### Markets

Ranked by volume, because "the top 50 Kalshi markets" should mean the ones people trade.
Kalshi's own flat market listing is dominated by untraded multi-leg parlay legs — of the first
1,200 it returns, 64 had any volume at all. This actor reads the event-level API instead, where
627 of 803 markets sampled were actively traded.

| Field | Description |
|---|---|
| `ticker` | Unique market id, e.g. `KXELONMARS-99` — use this for the other two modes |
| `question` | Self-identifying question text (see note below) |
| `subtitle` | What a YES resolves to, when one question is split across outcomes |
| `yesPrice`, `noPrice` | Implied probability, 0..1 |
| `spread` | Bid/ask gap |
| `volume`, `openInterest` | Contracts traded / contracts outstanding |
| `volumeUnit` | Always `contracts` here. Polymarket's `volume` is dollars — the field says which you have, so a cross-venue query cannot silently compare the two. |
| `closeTime`, `status`, `resolvedOutcome` | Lifecycle |

**On `question`:** Kalshi splits multi-outcome questions into one market per outcome and gives
them all the same title — 138 of 803 live markets shared their title with another market, so two
rows would read identically at different prices. Worse, some titles arrive with the subject
missing (`"Will  become President of the United States?"`). This actor rebuilds the question from
the event so every row identifies itself. `ticker` remains the unique key.

### Order book

Full L2 depth, normalized to 0..1 probability. Kalshi quotes both sides as bids, so a resting
no-bid at 0.17 is published here as a yes-ask at 0.83 — the book reads like any other exchange's.

`bestBid`, `bestAsk`, `midPrice`, `spread`, plus `bids[]` and `asks[]` with price and size.

**A book with no bids and no asks is not returned and not charged.** An empty book is
indistinguishable from a broken parser, so this actor treats it as a failure worth telling you
about rather than a row worth billing.

### Trades

| Field | Description |
|---|---|
| `yesPrice`, `noPrice` | The probability this trade printed at |
| `count` | Contracts (each settles at $1) |
| `value` | What the YES buyer paid |
| `takerSide` | Which side was the aggressor — the direction that moved the price |
| `isBlockTrade` | Negotiated off-book size |
| `ts` | Venue timestamp |

Each trade carries a `summary` with count, contracts, volume, aggressor split, and a **single
volume-weighted average price**. That single VWAP is honest here — verified across 600 live
trades, a Kalshi market's no price is always exactly `1 - yes`, so there is one price series.
Block trades are excluded from the VWAP because they print away from the book.

⚠️ **The VWAP covers exactly the trades you fetched, and trades come newest-first.** It is not the
market's lifetime average unless you asked for enough rows to reach the market's first trade.
Measured on KXALIENS-27: the newest **100** trades average **0.0725**, all **26,910** average
**0.1207** — the same field, 40% apart. The summary therefore carries `oldestTradeAt`,
`newestTradeAt` and `truncated`, so you can always see which window you are looking at. If
`truncated` is true, raise **Max results** to go further back.

### Limits, stated up front

- **No wallet or transaction hash.** Kalshi is a regulated exchange, not a blockchain. Wallet-level
  whale tracking is not possible here — that is a Polymarket-only capability.
- **`liquidity` is always `null`.** Kalshi's API returned 0.0000 for it on all 803 markets
  sampled, including one with 167k volume. Reporting 0 would claim a market has no liquidity when
  it has a deep book, so this actor reports nothing rather than something false.
- **Snapshots, not a stream.** Each run captures a moment.

### Use cases

Quant research and backtesting, odds aggregation, cross-venue arbitrage against Polymarket,
market-making analytics, AI agents that need live probability data.

***

#### For the developer (not shown on the Store)

Thin wrapper over the private `scraper-gateway`; contains no scraping logic. Set Actor
**environment variables** (secret): `SCRGW_URL`, `SCRGW_SECRET`. Pay-per-event events:
`market-returned` ($0.005), `orderbook-snapshot` ($0.02), `fill-returned` ($0.002).
Deploy: `apify push --force`.

# Actor input Schema

## `mode` (type: `string`):

markets = live odds, ranked by traded volume · orderbook = full L2 depth for given tickers · fills = executed trades for given tickers

## `tickers` (type: `array`):

Kalshi market tickers, e.g. KXELONMARS-99. The same identifier works for both order book and trades. Run mode 'markets' first to discover them — every row carries its ticker. Repeated tickers are ignored: each distinct ticker is fetched and charged once.

## `limit` (type: `integer`):

Hard cap on rows for the WHOLE run — across every market you submit, not per market — and therefore on what the run costs. Defaults to 100 so a first run is cheap. For the `fills` mode this also decides how far back the trade history reaches: trades come newest-first, so a low limit gives you recent trades, not the whole market. That matters because the summary's VWAP is computed over exactly what was fetched — on one measured market the newest 100 trades gave 0.0725 while all 26,910 gave 0.1207. The maximum is 50,000; at $0.002 per trade that run costs $100.

## `proxy` (type: `string`):

Optional public HTTP/HTTPS proxy. Leave empty to use the default egress.

## Actor input object example

```json
{
  "mode": "markets",
  "tickers": [
    "KXELONMARS-99"
  ],
  "limit": 100
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "tickers": [
        "KXELONMARS-99"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("dirtycode/kalshi-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "tickers": ["KXELONMARS-99"] }

# Run the Actor and wait for it to finish
run = client.actor("dirtycode/kalshi-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "tickers": [
    "KXELONMARS-99"
  ]
}' |
apify call dirtycode/kalshi-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=dirtycode/kalshi-api",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/VBbFfIKoogn4ubA40/builds/Yfcp5LGYHV3eAuH8F/openapi.json
