This repository contains a set of Python scripts designed to find equivalent binary markets across Kalshi and Polymarket, use an LLM via OpenAI and web search via Exa to generate an independent prediction, and then calculate the trading "edge" on both platforms.
The project is structured around three main scripts:
find_equiv_markets.py: A utility script to automatically search Kalshi and Polymarket APIs, use a Sentence Transformer and FAISS vector index to find markets with similar titles (i.e., equivalent questions), and save potential matches to a CSV file for manual review.
analyst.py and main.py: These scripts form the core prediction engine.
-
analyst.pyhandles API interactions with OpenAI (for prediction and question generation) and Exa (for web information retrieval). -
main.pyfetches the current prices from both Kalshi and Polymarket, runs the prediction viaBetAnalyst, and calculates the trading edge against the model's prediction. This logic is intended to be hosted on Cerebrium -
compare.py: This script reads the market pairs from the CSV, asynchronously calls the hosted prediction endpoint for each pair, and compiles statistics on the trading edge and which platform offers a better opportunity more frequently.
You will need API keys for the following services:
-
OpenAI: For the large language model (
BetAnalystclass). -
Exa: For semantic search/information retrieval (
BetAnalystclass). -
Cerebrium (or similar hosting platform): To deploy the
main.pyandanalyst.pylogic as a prediction endpoint.
Create a .env file in your project root to store your keys:
OPENAI_API_KEY="your_openai_key" EXA_API_KEY="your_exa_key"
Install the required Python packages:
pip install -r requirements.txt- Host the prediction service by deploying
main.pyandanalyst.pyon Cerebrium to expose apredictendpoint that runs theBetAnalystlogic. - Run
find_equiv_markets.pyto identify equivalent Kalshi and Polymarket markets and export the candidate pairs to a CSV file. - Execute
compare.py, which loads the CSV pairs, calls the hosted prediction endpoint for each pair, and aggregates the edge statistics to highlight the most favorable markets.