Making Markets on Kalshi
Published 2025-2-16
Update: 2025-2-17: This made it to the front page of Hacker News! Feel free to comment on the discussion page: https://news.ycombinator.com/item?id=43073377
I built a market making algorithm for Kalshi, an event futures exchange. The algorithm dynamically places bids and asks to capture the spread while managing inventory risk. It supports multiple strategies running in parallel, each with its own configuration. The codebase is located at https://github.com/rodlaf/kalshimarketmaker.
How It Works
At its core, the algorithm follows the Avellaneda-Stoikov model for optimal market making. It adjusts bid and ask prices based on factors like inventory, volatility, and time horizon. Orders are placed via the Kalshi trading API.
Each strategy is defined in config.yaml
, specifying market tickers, order limits, and
risk parameters. runner.py
loads all strategies and executes them concurrently using
threads.
Order Placement & Inventory Management
The market maker adjusts orders based on:
- Reservation price: A dynamically adjusted mid-price that incorporates inventory risk.
- Optimal spread: The bid-ask spread is widened or tightened depending on risk appetite and market conditions.
- Order expiration: Orders expire after a set time to avoid stale pricing.
If an order is no longer optimal, the system cancels and replaces it with a better-priced one.
Deployment
The system is designed to run on fly.io
using Docker. The setup is minimal:
- Define strategies in
config.yaml
- Deploy with
flyctl deploy
- Monitor live trades with
flyctl logs
Limitations & Future Work
Right now, orders are fully canceled and re-placed instead of being modified. This isn't ideal in a high-frequency setting. The bot also doesn't account for market impact, meaning large trades could move the price against itself.
A proper backtesting framework would also help evaluate strategies before deployment.
Code
The full codebase is structured as follows:
- .gitignore
- Dockerfile
- README.md
- config.yaml
- mm.py
- runner.py
mm.py
contains the market making logic.runner.py
loads and executes multiple strategies.config.yaml
holds per-strategy settings.- The
Dockerfile
allows for containerized deployment.
Conclusion
This project is an experiment in automated market making. It runs, it trades, and it logs everything. There's room for improvement, but it’s a solid starting point for algorithmic trading on Kalshi.