This project allows you to detect arbitrage opportunities in prediction markets like Polymarket, calculate the optimal combination of bets to maximize profit, and test the algorithm using both real Polymarket data and local example datasets.
-
Clone the repository:
git clone https://github.com/MauroPerna/betting-arbitrage.git cd betting-arbitrage -
Create a virtual environment with conda:
conda create -n betting-prediction-venv python=3.10 conda activate betting-prediction-venv
-
Install the dependencies:
pip install -r requirements.txt
By default, the main script (main.py) can be run in test mode using the data from the file data/data.json.
if __name__ == '__main__':
main(test=True) # Test mode, uses local JSONpython main.pyTo use the Polymarket API and search for real-time arbitrage:
if __name__ == '__main__':
main(test=False) # Polymarket mode, uses the real APIpython main.pyArbitrage consists of taking advantage of price/probability differences in a market to secure a risk-free profit by betting on all possible outcomes of an event.
In Polymarket, the "price" for each outcome represents its implied probability (e.g., 0.18 means 18%). If the sum of the probabilities of all outcomes in a market is less than 1, there is a theoretical opportunity for arbitrage.
Because you can allocate your funds across all outcomes so that, regardless of the result, your profit is equal and positive.
Let an event have n possible outcomes with prices (probabilities)
For each outcome
Where:
The net profit if outcome
The guaranteed net profit will be the minimum of all profit_i (it must be greater than zero for there to be real arbitrage).
- For real arbitrage, the sum of probabilities must be strictly less than 1 and the minimum profit must be positive.
- The script prints the best combination of bets and the guaranteed profit (if it exists).
betting-arbitrage/
├── main.py
├── utils.py
├── requirements.txt
└── data/
└── data.json