Simple market-making algorithm for Kalshi prediction markets. Provides two-way quotes for a single contract. Uses the fastest Python libraries and the Avellaneda-Stoikov model.
- This is a minimal example and does not include risk checks or robust error handling. Many unexpected situations can arise in automated trading, especially on Kalshi. I do not recommend using this in production.
- This is an open-source project. It is not intended to be profitable.
-
Install uv if you do not already have it installed. It is a very good Python package manager.
-
Create a virtual environment and install dependencies:
uv venv
uv sync- Create a config file:
cp config.json.sample config.jsonEdit config.json with your Kalshi API key ID, private key path, and target market ticker.
uv run main.pyThe script will check exchange status, load positions and resting orders, and begin quoting.
config.json fields:
key_id: Kalshi API key ID.key_path: path to your private key file.market_ticker: Kalshi market ticker to trade.
Strategy parameters live near the top of strategy.py:
POSITION_LIMIT: max inventoryORDER_SIZE: size per quoteGAMMA,DAILY_PRICE_VARIANCE,KAPPA: Avellaneda-Stoikov parameters
This project makes use of the fastest Python libraries I could find:
- uv for package management (package manager benchmarks)
- httpx for HTTP requests (HTTP library benchmarks)
- picows for WebSockets (WebSockets library benchmarks)
- msgspec for JSON [de]serialization (JSON serialization library benchmarks)
Credit to @BeatzXBT. I discovered picows and msgspec through his mm-toolbox repo.