TruthMarket AI is a sophisticated sports prediction engine that analyzes prediction market data from Polymarket and compares it against historical performance models. The system identifies overpriced and underpriced betting opportunities by calculating divergences between market probabilities and model estimates based on ELO ratings, historical success, and recent form.
The application consists of several components:
- Data Collection: Fetches live market data from Polymarket's Gamma API
- Historical Analysis: Uses comprehensive historical data for World Cup, NBA, and UEFA Champions League
- Model Calculation: Computes fair probabilities using a weighted model (50% ELO, 30% historical titles, 20% recent form)
- Signal Generation: Identifies betting opportunities where market odds diverge significantly from model estimates
- Web Interface: Provides a modern, responsive dashboard to visualize results
- Multi-Sport Support: World Cup 2026, NBA Championship 2026, UEFA Champions League 2025-26
- Explainable AI: Every signal comes with detailed reasoning and confidence scores
- Real-time Data: Fetches live market data from Polymarket
- Visual Dashboard: Premium web interface with team logos, confidence gauges, and sparklines
- API Endpoints: RESTful API for programmatic access
truthmarket/
├── app.py # Flask web application
├── main.py # Command-line analysis runner
├── fetcher.py # Polymarket API client
├── engine.py # Analysis engine and modeling
├── data.py # Historical sports data
└── results.json # Generated analysis output
- Python 3.8+
- pip package manager
-
Clone or download the project files
-
Install dependencies
pip install flask requests
Or using requirements.txt (create if not present):
pip install -r requirements.txt
-
Verify installation
python -c "import flask, requests; print('Dependencies installed successfully')"
-
Execute the main analysis script
python main.py
This will:
- Fetch live market data from Polymarket for all supported sports
- Run the analysis engine against historical data
- Generate signals for overpriced/underpriced opportunities
- Save results to
results.json
-
Expected output:
=================================================================== TRUTHMARKET AI — Sports Decision Engine Prediction markets vs historical reality =================================================================== [1/3] Fetching live Polymarket data... Fetching worldcup... → 32 markets found Fetching nba... → 30 markets found Fetching ucl... → 32 markets found [2/3] Running analysis... ── FIFA World Cup 2026 ── Analyzed: 32 teams Signals → BET AGAINST: 8 | FOLLOW: 12 | HOLD: 12 [3/3] Saving results.json... =================================================================== DONE. results.json ready. ===================================================================
-
Start the Flask application
python app.py
-
Open your browser and navigate to:
http://localhost:5000 -
API Access: The application also provides REST endpoints:
GET /api/analyze?sport=worldcup|nba|ucl
- World Cup: FIFA official records (1930-2022), ELO ratings from eloratings.net
- NBA: Official NBA records (1946-2025), recent performance metrics
- UEFA Champions League: UEFA official records (1955-2025), squad valuations
- Polymarket Gamma API: Live prediction market odds
- No authentication required for public market data
- Real-time updates available
The fair probability model uses three weighted signals:
- ELO Rating (50%): Current team strength based on international football ratings
- Historical Success (30%): Tournament titles and final appearances (with Laplace smoothing)
- Recent Form (20%): Performance in the most recent tournament season
- BET AGAINST: Market probability > Model probability + 5 percentage points
- FOLLOW MARKET: Market probability < Model probability - 5 percentage points
- HOLD: Probabilities align within ±5 percentage points
Confidence scores (50-99) are calculated based on divergence magnitude:
- ±5pp → 50% confidence
- ±15pp → 85% confidence
- ±30pp+ → 99% confidence
Currently supported sports and their Polymarket event slugs:
SPORT_SLUGS = {
"worldcup": "2026-fifa-world-cup-winner-595",
"nba": "2026-nba-champion",
"ucl": "uefa-champions-league-winner",
}SIGNAL_THRESHOLD = 5.0 # Percentage points for signal generation
# Model weights
ELO_WEIGHT = 0.50
HISTORICAL_WEIGHT = 0.30
RECENT_WEIGHT = 0.20Results are saved to results.json with the following structure:
{
"generated_at": "2026-04-08T12:00:00Z",
"sports": {
"worldcup": {
"label": "FIFA World Cup 2026",
"total_markets": 32,
"analyzed": 32,
"summary": {
"bet_against": 8,
"follow_market": 12,
"hold": 12
},
"results": [
{
"team": "Argentina",
"team_resolved": "Argentina",
"market_prob": 12.5,
"model_prob": 18.2,
"divergence": -5.7,
"signal": "FOLLOW MARKET",
"signal_short": "follow",
"color": "green",
"confidence": 65,
"explanation": "Argentina: 3 historical titles signal structural dominance...",
"logo_url": "https://flagcdn.com/h40/ar.png",
"breakdown": {
"elo": 2140,
"titles": 3,
"finals": 5,
"recent": "W"
}
}
]
}
}
}-
Import Errors: Ensure Flask and requests are installed
pip install flask requests
-
Network Errors: Check internet connection for Polymarket API access
-
Empty Results: Verify Polymarket event slugs are current
-
Web App Not Loading: Ensure port 5000 is available
Enable debug logging by modifying print statements to use the logging module:
import logging
logging.basicConfig(level=logging.DEBUG)- Additional Sports: Expand to more leagues and tournaments
- Advanced Modeling: Incorporate player statistics, injuries, weather
- Real-time Updates: WebSocket connections for live market changes
- Backtesting: Historical validation of model performance
- Machine Learning: Neural networks for probability estimation
- Mobile App: React Native companion application
- Dark/Light Theme: Theme toggle in the header with local persistence.
- Improved Sharing: Signal-level sharing with native Web Share fallback to clipboard.
- Comparison Sharing: Select 2-4 teams across cards and share a consolidated comparison text.
- Faster World Cup Load:
- Removed per-market artificial delay in fetch parsing.
- Added API analysis response cache in
app.pyfor repeated requests. - Staggered non-primary sport loads on frontend to prioritize first paint.
An updated CDC is available here:
docs/CDC.md
Generate the architecture diagram (Mermaid format) with:
python scripts/generate_architecture_diagram.pyOutput file:
docs/architecture.mmd
This project is for educational and research purposes. Please respect Polymarket's terms of service and applicable gambling regulations in your jurisdiction.
Contributions welcome! Areas for improvement:
- Additional data sources
- Model refinements
- UI/UX enhancements
- Test coverage
- Documentation
For questions or feedback, please examine the code and analysis methodology in the source files.