This Python script scrapes Kalshi's public API to find binary event contracts that are priced for low probability (i.e., offering potentially high payouts if they resolve to "Yes"). It focuses on markets that resolve to $1 if the "Yes" outcome occurs.
- Fetches currently open/active markets from Kalshi.
- Filters markets based on user-defined criteria:
- Minimum and Maximum "Yes" ask price (in cents).
- Minimum open interest.
- Minimum 24-hour volume.
- Handles API pagination to retrieve all available markets.
- Sorts the found markets primarily by "Yes" price (ascending) and secondarily by open interest (descending).
- Outputs the results to the console.
- Saves the results to a CSV file named
kalshi_high_payout_markets.csv
.
The script makes GET requests to Kalshi's trade-api/v2/markets
endpoint. It then processes the JSON response, applying the configured filters to identify target markets. The URLs for the markets are constructed based on the event_ticker
and ticker
fields provided by the API.
You can adjust the filtering behavior by modifying the following variables at the top of kalshi.py
:
MIN_YES_PRICE_CENTS
: The minimum "Yes" ask price (in cents) for a market to be considered (e.g.,2
for $0.02).MAX_YES_PRICE_CENTS
: The maximum "Yes" ask price (in cents) (e.g.,10
for $0.10).MIN_OPEN_INTEREST
: The minimum open interest required (e.g.,5
).MIN_VOLUME_24H
: The minimum 24-hour volume required (e.g.,5
).FETCH_ALL_PAGES
: Set toTrue
to scan all available market pages, orFalse
to only scan the first page (quicker for testing).CSV_FILENAME
: The name of the output CSV file (default:kalshi_high_payout_markets.csv
).
- Python 3.x
requests
librarypandas
library
-
Create a virtual environment (recommended):
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install requests pandas
-
Configure the script: Open
kalshi.py
and adjust the configuration variables at the top to your preferences. -
Run the script:
python kalshi.py
-
Check the output:
- The script will print a summary of found markets to the console.
- A CSV file (e.g.,
kalshi_high_payout_markets.csv
) will be created in the same directory with the detailed results.
- API Stability: This script uses an API endpoint that Kalshi provides for its trading interface. Kalshi may change or restrict access to this API without notice, which could break the script.
- Rate Limiting: Making excessive requests to the API could result in your IP address being temporarily or permanently rate-limited or blocked. The script includes a 1-second delay between fetching pages.
- Terms of Service: Ensure your use of this script complies with Kalshi's Terms of Service. Automated scraping can sometimes be against ToS.
- Not Financial Advice: This script is for informational and educational purposes only. The markets identified are, by definition, considered low probability. Investing in such markets carries significant risk. This is not financial advice.
- URL Accuracy: Market URLs are constructed based on API data. If a link leads to "Market Not Found," it could be due to the market's lifecycle (e.g., recently closed) or temporary inconsistencies.