A Python scanner can compare prediction market prices by polling multiple market APIs or scraped pages, normalizing the data into a common format, and then calculating price differences or arbitrage opportunities across platforms. You enter the markets you want to monitor and the scan interval, and the script returns a table of price mismatches, implied probabilities, and potential edges. This guide explains the core logic, the code structure, and the practical pitfalls you will encounter when building such a scanner.
Formula
The core comparison is simple: you subtract the price of the same outcome on two markets. The formula for the price difference is:
Difference = Price_Market_A – Price_Market_B
where both prices are in the same currency (typically USD) and represent the cost to buy one share that pays $1 if the event occurs. The arbitrage edge, when you can buy the outcome on the cheaper market and sell (or bet against) on the more expensive one, is:
Edge = (Price_A + Price_B) – 1
expressed as a percentage. If the sum of the two prices is less than 1, a theoretical arbitrage exists. The implied probability from a single price is simply Price × 100 (in percent).
Worked Example
Using the default values from the calculator: Market A has a price of 0.55, Market B has a price of 0.48.
- Price difference = 0.55 – 0.48 = 0.070 (7 cents)
- Arbitrage edge = (0.55 + 0.48) – 1 = 0.03, or 3%
- Implied probability on A = 0.55 × 100 = 55%
- Implied probability on B = 0.48 × 100 = 48%
The difference of 7 cents means that if you could buy on B and sell on A, you would lock in a 7-cent profit per share before fees. The 3% edge is the return on the combined trade. In practice, transaction fees and bid-ask spreads will eat into that edge, so you need to filter for edges above your cost threshold.
Why Compare Prediction Market Prices?
Prediction markets like Polymarket, PredictIt, and Kalshi list prices for the same events—elections, economic data releases, sports outcomes—but those prices often diverge. The reasons include different liquidity pools, varying fee structures, trading halts, and the fact that some markets are only open to certain users. A scanner that continuously compares prices helps you spot:
- Arbitrage opportunities where you can buy low on one market and sell high on another.
- Price discovery—a sudden move on one platform may signal news that the other hasn’t priced in yet.
- Market efficiency—if two markets consistently disagree, one may be mispriced relative to the other.
For a trader, the scanner is a monitoring tool, not a trading bot. It alerts you to discrepancies so you can decide whether to act.
How the Scanner Works
The basic architecture of a Python price scanner has three stages: data collection, normalization, and comparison.
- Data collection: You fetch prices from each market’s API. For example, Polymarket has a public API that returns the current price for each outcome token. PredictIt has an API that returns contract prices. Kalshi provides a REST API. If no API exists, you may scrape the website’s HTML, but that is fragile and slower.
- Normalization: Each market uses a different price format. Polymarket prices are in USDC (a stablecoin) and range from $0.01 to $0.99. PredictIt prices are in cents (e.g., 55 cents) but you must divide by 100 to get a decimal. Kalshi uses a similar decimal format. You also need to map the same event and outcome across platforms—e.g., “Will Biden win the 2024 election?” on Polymarket may be a single market, while PredictIt has multiple contracts like “Democratic nominee” and “President after 2024”. You must define a mapping table that links the exact question and outcome.
- Comparison: After normalizing, you subtract the prices and compute the edge. You might also compute the mid-price (average of bid and ask) if the API provides order book data, because the last trade price can be stale.
The scanner runs on a loop, sleeping for your chosen interval (e.g., 60 seconds) between fetches. It stores the results in a list or a database, and you can print only the rows where the difference exceeds a threshold.
Choosing the Right Data Source
Your scanner is only as good as the data it pulls. The main options are:
- Official APIs—most reliable, but they have rate limits and may require an API key. Check the documentation for endpoints and update frequency.
- Web scraping—use libraries like BeautifulSoup or Selenium to parse HTML. This is slower and breaks when the site changes its layout. Only use it when no API exists.
- Third-party aggregators—some sites already compare prices across prediction markets. You could scrape those instead, but you are adding a layer of indirection and potential staleness.
For a serious scanner, you want real-time data. Most prediction market APIs update prices every few seconds, but the exact latency varies. Test the response time and the last-updated timestamp to ensure you are not comparing stale prices.
Common Pitfalls and How to Avoid Them
Building a scanner is straightforward, but several mistakes can ruin your results:
- Ignoring fees: PredictIt charges a 10% fee on profits, and Polymarket has no trading fees but you pay gas fees for blockchain transactions. Always subtract expected fees from the edge before considering a trade.
- Bid-ask spread: The last price may not be executable. Use the best bid and ask from the order book. If you can buy at the ask and sell at the bid, the spread will be wider than the last-price difference.
- Liquidity constraints: A price difference may exist, but you might not be able to trade enough volume to make a profit. Check the order book depth.
- Event mapping errors: The same event can have different definitions. For example, “Will Trump be the Republican nominee?” on one market may be a single binary, while another market has multiple candidates. Ensure you are comparing the same outcome.
- Timezones and deadlines: Markets close at different times. A price difference may be due to one market having already closed. Always check the market status.
Sample Python Code Structure
Here is a minimal example of how the scanner loop might look (using pseudocode for clarity):
import time
import requests
def fetch_polymarket(outcome_id):
# API call returns price
return price
def fetch_predictit(contract_id):
# API call returns price in cents, divide by 100
return price / 100
def compare(outcome):
price_a = fetch_polymarket(outcome['poly_id'])
price_b = fetch_predictit(outcome['predictit_id'])
diff = price_a - price_b
edge = (price_a + price_b) - 1
if abs(diff) > 0.02: # threshold of 2 cents
print(f"{outcome['name']}: diff={diff:.3f}, edge={edge:.2%}")
while True:
for outcome in event_map:
compare(outcome)
time.sleep(60)
This is a skeleton. In a real implementation, you would add error handling (e.g., retry on timeout), logging, and a way to store historical data for backtesting.
Costs and Practical Considerations
Running a scanner is cheap in terms of computing resources—a simple script on a VPS costs a few dollars a month. The main costs are:
- API rate limits: If you poll too frequently, you may get blocked. Respect the documented limits and use exponential backoff.
- Data storage: If you store every price tick for months, you will accumulate a lot of data. Use a database like SQLite or a time-series database.
- Trading costs: The scanner itself is free, but acting on the opportunities involves fees, spreads, and possibly gas costs on blockchain-based markets.
There is also the opportunity cost of your attention—you need to monitor the alerts and decide quickly, because price discrepancies close fast.
Safety and Legal Notes
Prediction markets are regulated differently by jurisdiction. Some are illegal in certain countries, and some platforms restrict who can trade. Before building a scanner, verify that you are allowed to access and trade on the platforms you plan to use. Also, be aware that automated trading may violate a platform’s terms of service. This article is for educational purposes; you are responsible for complying with all applicable laws and rules.
Frequently Asked Questions
Can I make money with a prediction market scanner?
Potentially, but the scanner only identifies price differences. Whether you profit depends on fees, spreads, liquidity, and how quickly you can execute. Many discrepancies are tiny and vanish before you can act. Treat it as a research tool, not a money printer.
How often should I scan?
It depends on the market’s volatility and your trading style. For fast-moving events like election nights, you might scan every few seconds. For slower markets, scanning every minute is enough. Be mindful of API rate limits—polling too often can get you banned.
Do I need to know web scraping?
Only if a market lacks an API. Most major prediction markets have official APIs, so you can avoid scraping entirely. If you do scrape, use a robust parser and handle changes in the HTML structure.
What is the best programming language for this?
Python is the most common because of its libraries for HTTP requests, parsing, and data analysis. Other languages like JavaScript or Go can work too, but Python has the largest ecosystem for this kind of task.
How do I handle different time zones in market deadlines?
Convert all timestamps to UTC in your code. When comparing markets, check that both are still open and have the same closing time. If one market has closed, its price is frozen and should not be compared.
Can I use the scanner to bet on sports?
Yes, prediction markets include sports events. The same principles apply—compare prices across platforms that list the same game outcome. However, sports markets are often more efficient, so edges may be smaller.
Related
Formula used
in t | Scan interval (seconds) | s | 60 | 1 | 3600 in a | Price on Market A | USD | 0.55 | 0 | 1 in b | Price on Market B | USD | 0.48 | 0 | 1 out diff | Price difference | USD | a - b | 3 out arb | Arbitrage edge | % | ((a + b) - 1) * 100 | 2 out prob_a | Implied prob. A | % | a * 100 | 1 out prob_b | Implied prob. B | % | b * 100 | 1
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- CentOS Stream for Developers: A Practical Guide
- Hide PHP Version HTTP Header: How To
- How to Replace a Game Controller Battery Safely
- Man-Sized 3D Printer? Why You Probably Don’t Need One100.0 cm³/h
- Scroll Horizontally with Mouse Wheel by Holding Shift5.00 min/km
- iPadOS 16 Supported Devices: Full List