Python SDK for the KalshiBook L2 orderbook data API
Project description
KalshiBook
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)orsync=Falsefor async workflows - Auto-pagination --
PageIteratorhandles 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
- Getting Started -- Installation, first queries, DataFrames
- Authentication -- API keys, environment variables, error handling
- API Reference -- Complete SDK reference from source
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
735c7db20251a75c94afec81ebda0f7df0807d82e0838511a54800d3b0030dce
|
|
| MD5 |
daa7ce483955556004b3684e7e30f737
|
|
| BLAKE2b-256 |
c7e04df9c0462d0aa6cf5da68d9a70a0fdcbb03d2860bc0ed38af9ab976bd54e
|
Provenance
The following attestation bundles were made for kalshibook-0.1.0.tar.gz:
Publisher:
publish.yml on clouvelai/kalshibook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kalshibook-0.1.0.tar.gz -
Subject digest:
735c7db20251a75c94afec81ebda0f7df0807d82e0838511a54800d3b0030dce - Sigstore transparency entry: 960807820
- Sigstore integration time:
-
Permalink:
clouvelai/kalshibook@c124de2f8320d83f233b1dd7abeaa80884aff866 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/clouvelai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c124de2f8320d83f233b1dd7abeaa80884aff866 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6b732779d14135bfb5f502f492561d4caeaa6e36d65919d03836ac7d52c4556
|
|
| MD5 |
b9ff58633438cc704fb5f0986bb74711
|
|
| BLAKE2b-256 |
3a77c80b4b0b7e10b5978c8d8e348a8dad271ab7e1d305d85cfa4d6c717fca93
|
Provenance
The following attestation bundles were made for kalshibook-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on clouvelai/kalshibook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kalshibook-0.1.0-py3-none-any.whl -
Subject digest:
f6b732779d14135bfb5f502f492561d4caeaa6e36d65919d03836ac7d52c4556 - Sigstore transparency entry: 960807880
- Sigstore integration time:
-
Permalink:
clouvelai/kalshibook@c124de2f8320d83f233b1dd7abeaa80884aff866 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/clouvelai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c124de2f8320d83f233b1dd7abeaa80884aff866 -
Trigger Event:
release
-
Statement type: