Skip to main content

Python SDK for the KalshiBook L2 orderbook data API

Project description

KalshiBook

PyPI version Python versions License: MIT

Python SDK for the KalshiBook L2 orderbook data API. Query historical orderbook snapshots, trades, OHLCV candles, market metadata, event hierarchies, and settlement records for Kalshi prediction markets.

Installation

pip install kalshibook

With optional pandas support for .to_df() conversion:

pip install kalshibook[pandas]

Quick Start

from datetime import datetime, timezone
from kalshibook import KalshiBook

client = KalshiBook("kb-your-api-key")

# Reconstruct an orderbook at a point in time
book = client.get_orderbook(
    "KXBTC-25FEB14-T98250",
    timestamp=datetime(2025, 2, 14, 12, 0, tzinfo=timezone.utc),
)
for level in book.yes[:5]:
    print(f"YES {level.price}c x{level.quantity}")

client.close()

Key Features

  • Typed responses -- All API responses are frozen dataclasses with full type annotations
  • Sync and async -- Use KalshiBook(api_key, sync=True) or sync=False for async workflows
  • Auto-pagination -- PageIterator handles multi-page results transparently for deltas and trades
  • DataFrame support -- Call .to_df() on any list response or paginated iterator
  • Comprehensive errors -- Typed exceptions for auth, rate limits, credits, and missing data
  • Auto-retry -- Rate-limited requests are retried with exponential backoff and jitter

Usage Examples

List markets

markets = client.list_markets()
for m in markets.data:
    print(f"{m.ticker}: {m.title}")

OHLCV candles

candles = client.get_candles(
    "KXBTC-25FEB14-T98250",
    start_time=start,
    end_time=end,
    interval="1h",
)
df = candles.to_df()  # requires kalshibook[pandas]

Paginated trades

for trade in client.list_trades("KXBTC-25FEB14-T98250", start, end):
    print(f"{trade.yes_price}c x{trade.count}")

Async

async with KalshiBook("kb-your-api-key", sync=False) as client:
    markets = await client.alist_markets()

Documentation

Full documentation with guides, examples, and API reference:

kalshibook.github.io/kalshibook

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kalshibook-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kalshibook-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file kalshibook-0.1.0.tar.gz.

File metadata

  • Download URL: kalshibook-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kalshibook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 735c7db20251a75c94afec81ebda0f7df0807d82e0838511a54800d3b0030dce
MD5 daa7ce483955556004b3684e7e30f737
BLAKE2b-256 c7e04df9c0462d0aa6cf5da68d9a70a0fdcbb03d2860bc0ed38af9ab976bd54e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalshibook-0.1.0.tar.gz:

Publisher: publish.yml on clouvelai/kalshibook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalshibook-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kalshibook-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kalshibook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6b732779d14135bfb5f502f492561d4caeaa6e36d65919d03836ac7d52c4556
MD5 b9ff58633438cc704fb5f0986bb74711
BLAKE2b-256 3a77c80b4b0b7e10b5978c8d8e348a8dad271ab7e1d305d85cfa4d6c717fca93

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalshibook-0.1.0-py3-none-any.whl:

Publisher: publish.yml on clouvelai/kalshibook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page