{"id":47403166,"url":"https://github.com/arshka/pykalshi","last_synced_at":"2026-04-01T20:01:15.760Z","repository":{"id":335948093,"uuid":"1147000463","full_name":"arshka/pykalshi","owner":"arshka","description":"Unofficial Python client for Kalshi's prediction markets API","archived":false,"fork":false,"pushed_at":"2026-03-27T22:28:55.000Z","size":1831,"stargazers_count":66,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-28T04:21:48.869Z","etag":null,"topics":["algorithmic-trading","api-client","finance","kalshi","kalshi-api","kalshi-trading-bot","market-data","prediction-markets","python","real-time","trading","websocket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arshka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-01T02:52:10.000Z","updated_at":"2026-03-27T22:28:59.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/arshka/pykalshi","commit_stats":null,"previous_names":["arshka/kalshi-api","arshka/kalshi-client"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arshka/pykalshi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshka%2Fpykalshi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshka%2Fpykalshi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshka%2Fpykalshi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshka%2Fpykalshi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arshka","download_url":"https://codeload.github.com/arshka/pykalshi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshka%2Fpykalshi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmic-trading","api-client","finance","kalshi","kalshi-api","kalshi-trading-bot","market-data","prediction-markets","python","real-time","trading","websocket"],"created_at":"2026-03-20T15:00:17.516Z","updated_at":"2026-04-01T20:01:15.749Z","avatar_url":"https://github.com/arshka.png","language":"Python","funding_links":[],"categories":["🧩 APIs","Data Source"],"sub_categories":["Prediction Markets"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets/pykalshi_logo_dark.svg\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"assets/pykalshi_logo_light.svg\"\u003e\n    \u003cimg alt=\"pykalshi logo\" src=\"assets/pykalshi_logo_light.svg\" width=\"70%\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n# PyKalshi\n\n[![PyPI version](https://img.shields.io/pypi/v/pykalshi.svg)](https://pypi.org/project/pykalshi/)\n[![Python versions](https://img.shields.io/pypi/pyversions/pykalshi.svg)](https://pypi.org/project/pykalshi/)\n[![Tests](https://github.com/ArshKA/pykalshi/actions/workflows/test.yml/badge.svg)](https://github.com/ArshKA/pykalshi/actions/workflows/test.yml)\n[![License](https://img.shields.io/pypi/l/pykalshi.svg)](https://github.com/ArshKA/pykalshi/blob/main/LICENSE)\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1cD1FJZSeEW2qThzi7IZQKtHxu3z3eWAO?usp=sharing)\n\nThe Python client for [Kalshi](https://kalshi.com) prediction markets. WebSocket streaming, automatic retries, pandas integration, and clean interfaces for building trading systems.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/jupyter_preview.png\" alt=\"Jupyter notebook rich display\" width=\"90%\"\u003e\n\u003c/p\u003e\n\n```python\nfrom pykalshi import KalshiClient, Action, Side\n\nclient = KalshiClient()\n\n# Place a trade\norder = client.portfolio.place_order(\"KXBTC-25MAR15-B100000\", Action.BUY, Side.YES, count_fp=\"10\", yes_price_dollars=\"0.45\")\norder.wait_until_terminal()  # Block until filled/canceled\n```\n\n## Features\n\n- **WebSocket streaming** - Real-time orderbook, ticker, and trade data with typed messages\n- **Automatic retries** - Exponential backoff on rate limits and transient errors\n- **Domain objects** - `Market`, `Order`, `Event` with methods like `order.cancel()`, `market.get_orderbook()`\n- **pandas integration** - `.to_dataframe()` on any list of results\n- **Jupyter support** - Rich HTML display for markets, orders, and positions\n- **Local orderbook** - `OrderbookManager` maintains state from WebSocket deltas\n- **Type safety** - Pydantic models and typed exceptions throughout\n\n## Installation\n\n```bash\npip install pykalshi\n\n# With pandas support\npip install pykalshi[dataframe]\n```\n\nGet your API credentials from [kalshi.com](https://kalshi.com/account/api) and create a `.env` file:\n\n```\nKALSHI_API_KEY_ID=your-key-id\nKALSHI_PRIVATE_KEY_PATH=/path/to/private-key.key\n```\n\n## Quick Start\n\n\u003e **Interactive demo:** [`examples/demo.ipynb`](examples/demo.ipynb) or [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1cD1FJZSeEW2qThzi7IZQKtHxu3z3eWAO?usp=sharing)\n\n### Browse Markets\n\n```python\nfrom pykalshi import MarketStatus, CandlestickPeriod\n\nclient = KalshiClient()\n\n# Search markets\nmarkets = client.get_markets(status=MarketStatus.OPEN, limit=100)\nbtc_markets = client.get_markets(series_ticker=\"KXBTC\")\n\n# Get a specific market\nmarket = client.get_market(\"KXBTC-25MAR15-B100000\")\nprint(f\"{market.title}: ${market.yes_bid_dollars} / ${market.yes_ask_dollars}\")\n\n# Market data\norderbook = market.get_orderbook()\ntrades = market.get_trades(limit=50)\ncandles = market.get_candlesticks(start_ts, end_ts, period=CandlestickPeriod.ONE_HOUR)\n```\n\n### Trading\n\n```python\nfrom pykalshi import Action, Side, OrderStatus\n\n# Check balance\nbalance = client.portfolio.get_balance()\nprint(f\"${balance.balance / 100:.2f} available\")\n\n# Place an order\norder = client.portfolio.place_order(market, Action.BUY, Side.YES, count_fp=\"10\", yes_price_dollars=\"0.50\")\n\n# Manage orders\norder.wait_until_terminal()  # Block until filled/canceled\norder.modify(yes_price=45)   # Amend price\norder.cancel()               # Cancel\n\n# View portfolio\npositions = client.portfolio.get_positions()\nfills = client.portfolio.get_fills(limit=100)\norders = client.portfolio.get_orders(status=OrderStatus.RESTING)\n```\n\n### Real-time Streaming\n\n```python\nfrom pykalshi import Feed, TickerMessage, OrderbookSnapshotMessage\n\nasync with Feed(client) as feed:\n    await feed.subscribe_ticker(\"KXBTC-25MAR15-B100000\")\n    await feed.subscribe_orderbook(\"KXBTC-25MAR15-B100000\")\n    await feed.subscribe_trades(\"KXBTC-25MAR15-B100000\")\n\n    async for msg in feed:\n        match msg:\n            case TickerMessage():\n                print(f\"Price: ${msg.price_dollars}\")\n            case OrderbookSnapshotMessage():\n                print(f\"Book: {len(msg.yes)} yes levels, {len(msg.no)} no levels\")\n```\n\n### Local Orderbook\n\n```python\nfrom pykalshi import Feed, OrderbookManager\n\nmanager = OrderbookManager()\n\nasync with Feed(client) as feed:\n    await feed.subscribe_orderbook(ticker)\n\n    async for msg in feed:\n        manager.apply(msg)\n        book = manager.get(ticker)\n        best_bid = book[\"yes_dollars\"][0] if book[\"yes_dollars\"] else None\n```\n\n### pandas Integration\n\n```python\n# Any list result has .to_dataframe()\npositions_df = client.portfolio.get_positions().to_dataframe()\nmarkets_df = client.get_markets(limit=500).to_dataframe()\nfills_df = client.portfolio.get_fills().to_dataframe()\n\n# Candlesticks and orderbooks too\ncandles_df = market.get_candlesticks(start, end).to_dataframe()\norderbook_df = market.get_orderbook().to_dataframe()\n```\n\n### Error Handling\n\n```python\nfrom pykalshi import InsufficientFundsError, RateLimitError, KalshiAPIError\n\ntry:\n    order = client.portfolio.place_order(...)\nexcept InsufficientFundsError:\n    print(\"Not enough balance\")\nexcept RateLimitError:\n    pass  # Client auto-retries with backoff\nexcept KalshiAPIError as e:\n    print(f\"{e.status_code}: {e.error_code}\")\n```\n\n## Examples\n\nSee the [`examples/`](examples/) directory:\n\n- **[demo.ipynb](examples/demo.ipynb)** - Interactive notebook with rich display examples\n- **[basic_usage.py](examples/basic_usage.py)** - Browse markets and check portfolio\n- **[place_order.py](examples/place_order.py)** - Place and manage orders\n- **[stream_orderbook.py](examples/stream_orderbook.py)** - WebSocket streaming patterns\n- **[momentum_bot.py](examples/momentum_bot.py)** - Simple trading bot example\n\n## Web Dashboard\n\nA real-time web dashboard is included for browsing markets, viewing orderbooks, and monitoring your portfolio. It serves as both a development tool and a reference implementation.\n\n```bash\npip install pykalshi[web]\nuvicorn web.backend.main:app --reload\n```\n\nSee [`web/`](web/) for details.\n\n## Why pykalshi?\n\n| | pykalshi | kalshi-python (official) |\n|---|:---:|:---:|\n| WebSocket streaming | ✓ | — |\n| Automatic retry/backoff | ✓ | — |\n| Rate limit handling | ✓ | — |\n| Domain objects | ✓ | — |\n| pandas integration | ✓ | — |\n| Jupyter display | ✓ | — |\n| Local orderbook | ✓ | — |\n| Typed exceptions | ✓ | — |\n| Pydantic models | ✓ | — |\n| Full API coverage | — | ✓ |\n\nThe official SDK is auto-generated from the OpenAPI spec. pykalshi adds the infrastructure needed for production trading: real-time data, error recovery, and ergonomic interfaces.\n\n## Links\n\n- [Kalshi API Reference](https://trading-api.readme.io/reference)\n- [kalshi-python (official SDK)](https://github.com/Kalshi/kalshi-python)\n\n---\n\n*This is an unofficial library and is not affiliated with Kalshi.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshka%2Fpykalshi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farshka%2Fpykalshi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshka%2Fpykalshi/lists"}