- Python 3.10+
- Kalshi API key (prod and/or demo)
- Running Kafka server (see here for more information)
- Assumes default port of 9092
To install the required packages, run:
pip install -r requirements.txtOnce all requirements are met, make sure that all necessary environment variables (like API keys) are set before running the application.
The system will look for the following Kalshi API keys:
KALSHI_PROD_EMAILKALSHI_PROD_PASSWORDKALSHI_DEMO_EMAILKALSHI_DEMO_PASSWORD
To switch between production and demo environments, change the kalshi_api variable in KalshiAPI.py to either prod_kalshi_api or demo_kalshi_api.
There are several services that can be run:
-
MarketDataService- Listens for market data events from Kalshi and pushes them to Kafka
-
MarketMonitor- Listens for market data events from Kafka and passes them to any handlers that are passed in
print_orderbookis an example of a handler that prints the current state of the orderbook to the terminal
-
User Strategies (
TestStrategy)- Strategies are effectively event listeners that listen for market data events and do something with them, whether that's logging, sending orders, notifying a user, etc.
TestStrategyis a simple example of a strategy that listens for market data events and sends a market order to Kalshi under certain conditions
-
OrderManagementSystem- Keeps track of open orders and positions sent from various strategies
-
To run the relevant services, use the
run.pyscript.- The
MarketDataServiceis run automatically when this script is run - The
--componentsflag allows you to specify which additional components to runmonitorwill run the market monitor withprint_orderbook, which will print the current state of the orderbook to the terminalstrategywill run the test strategy, which will listen for market data events and send a market order to Kalshi under certain conditions
- The
-
An example of how to run the system is:
python run.py --components monitor strategy --ticker POPVOTEMOVSMALLER-24
- This will run the market data service, and the market monitor with the test strategy
-
If you don't specify a ticker, the system will not automatically subscribe to markets in
market_listas defined inSeries.py