# Kalshi

> Kalshi prediction markets — markets, order books, candlesticks, trades and events

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/kalshi.json) contains the same setup facts for structured readers; choose one format.

## Runtime and release

Use DuckDB or Haybarn **2.0.1** with **VGI protocol 3.4**.
Catalog alias: `kalshi`. Release: [v1.5.1](https://github.com/Query-farm/vgi-kalshi/releases/tag/v1.5.1). Metadata generated: 2026-12-01T18:22:16+00:00.

## Choose where it runs

- On your machine: use an installation method below. No Query Farm account is required for local execution.
- Self-host: follow [the connector deployment instructions](https://github.com/Query-farm/vgi-kalshi) and [connection guide](https://query.farm/vgi/connect-to-a-worker/). Use your real endpoint and its authentication settings.
- Query Farm hosted: [create a deployment](https://auth.queryfarm.cloud/console/new?worker=kalshi). Hosting has a $10 monthly minimum per organization; usage and license fees may apply. Copy the deployment-specific ATTACH from the console.

## Service credentials and prerequisites

Market data is public; credentials are only for your own account (positions, balance).

Secret parameter required flags describe the upstream declaration; they do not override the service-level mode above. Keep secrets in environment variables or the deployment secret store. SQL values in angle brackets are placeholders, not automatic environment lookups. Native DuckDB and Haybarn 2.0.1 do not provide a SQL getenv() function, even when worker-supplied snippets mention it. Read environment variables in your application and pass credential values through client parameter bindings (for example, Python con.execute("CREATE SECRET stripe (TYPE stripe, api_key ?)", [os.environ["STRIPE_API_KEY"]]) after attaching the connector. Omit unused optional parameters and keep real values out of saved SQL and logs.

After installing VGI and attaching the connector, create the required secrets using your own values. Replace placeholders and omit unused optional parameters from the templates below.

### kalshi

Kalshi API credentials for authenticated access. Optional for market data, which is public. Provide key_id (the API Key ID) and private_key (its RSA or Ed25519 private key, PEM). Required by the margin_* account functions.
[Credential instructions](https://docs.kalshi.com/getting_started/api_keys)

```json
[
  {
    "name": "key_id",
    "type": "VARCHAR",
    "required": false,
    "redact": false,
    "description": "API Key ID shown on Kalshi's Account > API Keys page when the key is created"
  },
  {
    "name": "private_key",
    "type": "VARCHAR",
    "required": false,
    "redact": true,
    "description": "RSA or Ed25519 private key (PEM) downloaded once when the API key is created"
  }
]
```

```sql
CREATE SECRET kalshi (
    TYPE kalshi,
    key_id      '<key_id>',
    private_key '<PRIVATE_KEY>'  -- secret
);
```

ATTACH options (exact declarations; omitted defaults are unknown):

```json
[
  {
    "name": "auth",
    "type": "VARCHAR",
    "description": "How to treat the optional 'kalshi' secret: 'auto' (default) signs when one is present and uses public access otherwise; 'required' fails the query when none resolves; 'off' never signs.",
    "required": false,
    "default": "auto"
  }
]
```

## Install the extension

In stock DuckDB:

```sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
```

In Haybarn:

```sql
INSTALL vgi FROM community;
LOAD vgi;
```

## Attach the connector

The local recipes below pin the catalog release for repeatability. A public demo endpoint follows its deployed release.

### uvx

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

```sql
ATTACH 'kalshi' AS kalshi (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/vgi-kalshi@v1.5.1 vgi-kalshi'
);
```

### Docker

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

```sql
ATTACH 'kalshi' AS kalshi (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-kalshi:1.5.1'
);
```

## Compare active Bitcoin prediction markets

Service credentials required for this example: not declared by this example; check the connector requirements above.

```sql
SELECT ticker, title, yes_bid_dollars, yes_ask_dollars, volume_24h_fp FROM kalshi.main.markets('KXBTCD') WHERE status = 'active' ORDER BY volume_24h_fp DESC
```

- [kalshi.main.markets — table_function](https://query.farm/products/orchard/connectors/kalshi/objects/table_function.bWFpbg.bWFya2V0cw.md): exact declaration for this example.

Execution evidence: **captured_result**.

```json
{
  "status": "captured_result",
  "capturedAt": "2026-12-01T06:16:30+00:00",
  "engineVersion": "2.0.1",
  "protocolVersion": "3.4.0",
  "releaseTag": "v1.5.1",
  "sample": {
    "columns": [
      "ticker",
      "title",
      "yes_bid_dollars",
      "yes_ask_dollars",
      "volume_24h_fp"
    ],
    "types": [
      "VARCHAR",
      "VARCHAR",
      "DECIMAL(18,4)",
      "DECIMAL(18,4)",
      "DECIMAL(18,2)"
    ],
    "rows": [
      [
        "KXBTCD-26DEC0117-T57999.99",
        "Bitcoin price on Dec 1, 2026?",
        0.94,
        0.95,
        51336.78
      ],
      [
        "KXBTCD-26DEC0117-T58999.99",
        "Bitcoin price on Dec 1, 2026?",
        0.83,
        0.84,
        45391.41
      ],
      [
        "KXBTCD-26DEC0117-T61999.99",
        "Bitcoin price on Dec 1, 2026?",
        0.1,
        0.11,
        40964.99
      ],
      [
        "KXBTCD-26DEC0417-T54999.99",
        "Bitcoin price on Dec 4, 2026?",
        0.94,
        0.95,
        38539.47
      ],
      [
        "KXBTCD-26DEC0117-T62499.99",
        "Bitcoin price on Dec 1, 2026?",
        0.05,
        0.06,
        33608.57
      ]
    ],
    "more": true
  }
}
```

## Connector reference

Kalshi is a CFTC-regulated exchange for event contracts. A contract pays $1 if its question resolves YES and $0 if it resolves NO, so its price is the market's implied probability of that outcome.

### How the data is shaped

Kalshi nests in three levels, and nearly every question starts by picking one at the top:

- **Series** — a recurring question, such as KXBTCD for the Bitcoin daily price. This is the level the `series` table lists, and its ticker is the key almost everything else requires.
- **Event** — one occurrence of a series, with a single resolution date.
- **Market** — one strike within an event. This is what actually trades, and its ticker is what the per-market lookups take.

### Reading prices

Every `*_dollars` column is dollars per contract between 0 and 1, so a best bid of 0.62 is a 62% implied probability. They are `DECIMAL`, never `DOUBLE`: Kalshi sends exact fixed-point strings, and rounding them through a float would throw that away silently. Contract counts (`*_fp`) are decimals for the same reason.

### Access

No credentials are needed for market data. Kalshi's whole market-data surface is public. The four `margin_*` functions (`margin_positions`, `margin_balance`, `margin_risk`, `margin_funding_history`) read the key holder's own perps account and need a `kalshi` secret; RSA and Ed25519 keys both work, and a read-only key is the right kind. Order entry and transfers are out of reach: the worker has no write verb and its account paths are a fixed allowlist. Read-only by construction, not by configuration.

### Rate limits

Unauthenticated traffic is limited tightly enough that a handful of back-to-back requests draws an HTTP 429. A correlated `LATERAL` issues one request per input row, so a join across a whole series is hundreds of calls. Requests are retried with exponential backoff, and the per-market functions take a `cache_ttl` argument that turns repeated lookups of the same ticker into cache hits when a few seconds of staleness is acceptable.

### Sources

- [Kalshi](https://kalshi.com) — the exchange this data comes from.
- [Kalshi API documentation](https://docs.kalshi.com) — the public Trade API v2 this worker reads (`https://api.elections.kalshi.com/trade-api/v2`): series, events, markets, order books, candlesticks, trades, exchange status and the [historical archive](https://docs.kalshi.com/getting_started/historical_data).
- [Rate limits and tiers](https://docs.kalshi.com/getting_started/rate_limits) — the request budget that `cache_ttl` and the retry backoff are built around.
- [API keys](https://docs.kalshi.com/getting_started/api_keys) — needed for the `margin_*` account functions, or to sign market-data requests at a higher rate-limit tier, via a `kalshi` secret.
- [Perps API](https://docs.kalshi.com/perps_openapi.yaml) — the `/margin` endpoints the account functions read.

### Terms of use

The market data is Kalshi Inc.'s, not covered by this worker's MIT license, and is subject to the [Kalshi Data Terms of Use](https://kalshi-public-docs.s3.amazonaws.com/kalshi-data-terms-of-service.pdf) and the [Kalshi Developer Agreement](https://kalshi-public-docs.s3.amazonaws.com/Kalshi-Developer-Agreement.pdf). The Developer Agreement limits API use to facilitating a member's own trading on the exchange and restricts storing, aggregating or sharing the data without Kalshi's written authorization; read both before using this worker. This worker is not affiliated with or endorsed by Kalshi.

## Find the exact SQL object

[Browse 21 object declarations](https://query.farm/products/orchard/api/v1/connectors/kalshi/objects.json) or [search within this connector](https://query.farm/products/orchard/api/v1/search.json?kind=object&connector=kalshi&q=kalshi).

Follow one format of each needed object for complete argument types, defaults, named flags, return columns and examples. Existing links above can replace another search. For questions about hosting, credentials or supported operations, stop once the documentation answers the question; SQL and unrelated object lookups are unnecessary.

## Verification and interpretation

- Missing, null, or undeclared metadata means unknown; do not invent defaults, credential scope, platform support or endpoint URLs.
- Search is keyword retrieval, not proof of a capability. Read the exact object declaration before generating SQL.
- A table and a table function can have the same name. Preserve parentheses and use the matching overload and schema.
- Service credentials, external data availability and deployment authentication are separate requirements.
- Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL.

```json
{
  "generatedAt": "2026-12-01T18:22:16+00:00",
  "repository": "https://github.com/Query-farm/vgi-kalshi",
  "harvest": {
    "status": "ok",
    "method": "subprocess",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 7,
    "passed": 7,
    "failed": 0,
    "needs_credentials": 0,
    "location": "uvx --from git+https://github.com/Query-farm/vgi-kalshi@v1.5.1 vgi-kalshi",
    "transport": "subprocess",
    "environment": {
      "vgi_extension_version": "9773130dde",
      "haybarn_version": "2.0.1rc3",
      "engine_version": "v2.0.1",
      "python": "3.12.4",
      "platform": "darwin_arm64",
      "protocol_version": "3.4.0"
    },
    "checked_at": "2026-12-01T06:13:55+00:00"
  },
  "interpretation": "Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL."
}
```
