Real-time monitoring system for tracking large bets (whales) on Polymarket prediction markets.
This system monitors Polymarket's real-time data streams to track significant trading activity (≥$1,000 USD bets), providing insights into whale positions, win rates, and market movements.
- Real-time WebSocket monitoring of Polymarket trades
- Position tracking with P&L calculations
- Win rate analysis for whale traders
- Insider detection based on trading patterns
- Top 10 holders analysis for market concentration
- Volume spike detection for unusual market activity
- Flask API for data access
- Minimal dark-theme UI for visualization
┌─────────────────┐
│ Polymarket API │
│ (WebSocket) │
└────────┬────────┘
│
▼
┌─────────────────┐ ┌──────────────┐
│ whale_service.py│─────▶│ PostgreSQL │
│ (Data Collector)│ │ Database │
└─────────────────┘ └──────┬───────┘
│
┌───────────────────────┤
│ │
▼ ▼
┌─────────────────┐ ┌──────────────┐
│ pnl_updater.py │ │ app.py │
│ (Update P&L) │ │ (Flask API) │
└─────────────────┘ └──────┬───────┘
│
▼
┌──────────────┐
│ Frontend │
│ (HTML/JS) │
└──────────────┘
Poly-Sema/
├── src/ # Main source code
│ ├── whale_service.py # WebSocket listener for real-time trades
│ ├── app.py # Flask API server
│ ├── config.py # Configuration management
│ ├── pnl_updater.py # P&L calculation updater
│ ├── win_rate_updater.py # Win rate calculation
│ ├── update_positions.py # Position tracking
│ ├── top10_backfill.py # Top 10 holders analysis
│ ├── requirements.txt # Python dependencies
│ ├── templates/
│ │ └── polymarket.html # Frontend UI
│ └── DOCS/ # Technical documentation
├── DOCS/ # Widget specifications
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
PostgreSQL database polymarket_whale_monitor with schema polymarket:
whale_bets - Stores all whale transactions
- Trade details (tx_hash, timestamp, wallet, bet_size, side)
- Position metrics (avg_entry_price, position_size, unrealized_pnl)
- Win rate stats (total_trades, wins, losses, win_rate_percent)
- Market data (outcome, market_question, event_slug)
- Insider flags and top 10 holder percentages
market_cache - Caches market metadata
- Market questions, slugs, and URLs
- Prevents redundant API calls
- Python 3.8+
- PostgreSQL 12+
- 2GB RAM minimum
git clone <repository-url>
cd Poly-SemaCopy the example environment file and configure:
cp .env.example .envEdit .env and set:
DATABASE_URL- PostgreSQL connection stringDB_HOST,DB_PORT,DB_NAME,DB_USER,DB_PASSWORDMIN_WHALE_BET_USD- Minimum bet size to track (default: 1000)
Create the database and schema:
createdb polymarket_whale_monitor
psql -d polymarket_whale_monitor -c "CREATE SCHEMA IF NOT EXISTS polymarket;"The tables will be created automatically when you first run the services.
cd src
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtYou need to run multiple services:
Terminal 1: WebSocket Listener
cd src
source venv/bin/activate
python whale_service.pyTerminal 2: Flask API
cd src
source venv/bin/activate
python app.pyTerminal 3 (Optional): P&L Updater
cd src
source venv/bin/activate
python pnl_updater.pyTerminal 4 (Optional): Win Rate Updater
cd src
source venv/bin/activate
python win_rate_updater.pyOpen your browser:
http://localhost:8000
Get list of whale bets
Query Parameters:
limit(int, default: 100) - Number of recordssort(str, default: 'time') - Sort by 'time' or 'size'
Response:
{
"status": "success",
"data": [
{
"id": 1,
"timestamp": "2025-12-26T19:00:00Z",
"whale_wallet": "0x1234...5678",
"bet_size_usd": 15000.00,
"outcome": "YES",
"market_question": "Will Trump win 2024?",
"avg_entry_price": 0.65,
"position_size": 23076.92,
"unrealized_pnl_usd": 1500.00,
"unrealized_pnl_percent": 10.0,
"win_rate_percent": 65.5,
"total_trades": 42
}
],
"count": 1
}Get 24-hour statistics
Response:
{
"status": "success",
"data": {
"total_bets_24h": 156,
"total_volume_24h": 2345678.00,
"unique_whales_24h": 42
}
}Health check endpoint
All configuration is done through environment variables in .env:
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | - |
MIN_WHALE_BET_USD |
Minimum bet size to track | 1000 |
FLASK_HOST |
Flask server host | 127.0.0.1 |
FLASK_PORT |
Flask server port | 8000 |
FLASK_DEBUG |
Enable debug mode | True |
LOG_LEVEL |
Logging level | INFO |
cd src
pytest tests/This project uses:
- PEP 8 style guide
- Type hints where applicable
- Docstrings for all functions
Schema changes should be documented and applied manually. No ORM is used to keep dependencies minimal.
All services log to console with timestamps. Log levels:
- INFO: Normal operations
- WARNING: Recoverable errors
- ERROR: Critical failures
Check logs for:
# WebSocket listener
tail -f src/whale_service.log
# Flask API
tail -f src/flask_api.log- Check network stability
- Verify Polymarket WebSocket URL is current
- Review logs for error patterns
- Verify
MIN_WHALE_BET_USDthreshold - Check if whale_service.py is running
- Confirm database connection
- Verify PostgreSQL is running
- Check DATABASE_URL in .env
- Ensure database and schema exist
Expected resource usage:
- Memory: ~200MB per service
- CPU: <5% average
- Disk: ~1GB per week for whale_bets table
.envfile contains sensitive credentials - never commit to git- Default setup is localhost-only
- For production deployment:
- Use environment-based secrets
- Enable HTTPS
- Implement rate limiting
- Add authentication
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Check
/src/DOCSfor detailed widget specifications - Review logs for error messages
- Open an issue on GitHub
- WebSocket reconnection with exponential backoff
- Redis caching layer
- GraphQL API
- Mobile-responsive UI
- Real-time notifications
- Advanced analytics dashboard