# 🌑️ PolyWeather: Polymarket Weather Trading Monitor An intelligent monitoring and alerting system based on multi-source real-time meteorological data and Polymarket market pricing deviation analysis. ## πŸš€ Quick Start ### Requirements - **Python 3.11** (Required for `py-clob-client` dependency) - All dependencies installed: `pip install -r requirements.txt` ### Windows ```powershell # Option 1: Use Python 3.11 launcher py -3.11 run.py # Option 2: Activate virtual environment first .venv\Scripts\activate python run.py ``` ### Linux/VPS ```bash # Use screen to keep it running in background screen -S polyweather python3.11 run.py # Detach: Press Ctrl+A then D # Reattach: screen -r polyweather ``` This command launches: 1. **Monitoring Engine**: Scans markets 24/7, providing **85Β’-95Β’ Price Alerts** and **Market Anomalies**. 2. **Command Listener**: Handles Telegram commands and returns real-time signals. --- ## πŸ€– Telegram Bot Commands | Command | Description | Usage | | :---------------- | :---------------------- | :--------------------------------------------- | | `/signal` | **Get Trading Signals** | Returns Top 5 markets with earliest settlement | | `/city [name]` | **Query City Details** | Get market info, forecast & live temperature | | `/portfolio` | **View Portfolio** | Get real-time paper trading profit report | | `/status` | **Check Status** | Confirm if the monitoring engine is online | | `/help` | **Help** | Display all available commands | ### /city Command Example ``` /city chicago ``` Output: ``` πŸ“ Chicago Market Details ════════════════════ πŸ• Local Time: 08:30 πŸ“Š Open-Meteo Forecast πŸ‘‰ Today: High 38Β°F 02-08: High 42Β°F 02-09: High 45Β°F ✈️ Airport Obs (KORD) 🌑️ 32.0Β°F πŸ’¨ Wind: 12kt πŸ• Observed: 14:00 UTC πŸ“… 2026-02-07 Forecast:38Β°F ────────────────── πŸ”₯ 40-41Β°F: No 94Β’ β†’Buy NO πŸ”₯ 38-39Β°F: Yes 91Β’ β†’Buy YES ⭐ 36-37Β°F: No 87Β’ β†’Buy NO ``` Supported abbreviations: `chi` (Chicago), `nyc` (New York), `atl` (Atlanta), `sea` (Seattle), `dal` (Dallas), `mia` (Miami) --- ## 🎯 Smart Dynamic Position Strategy The system automatically decides the position size based on **Open-Meteo Weather Forecasts**, **Volume**, and **Price Locking Degree**: | Condition Combination | Size | Tag | Description | | ------------------------------------------ | ------- | ----------------- | -------------------------------- | | Price β‰₯90Β’ + Weather Support + High Volume | **$10** | πŸ”₯High Confidence | Triple confirmation, Heavy stake | | Price β‰₯90Β’ + Weather Support | **$7** | ⭐Mid Confidence | Double confirmation | | Price β‰₯92Β’ | **$5** | πŸ“ŒPrice Locked | Pure price locking | | Other 85-91Β’ | **$3** | πŸ’‘Probe | Minimum stake for probing | ### Weather Support Logic - **Buy NO**: Open-Meteo predicted temperature is **outside** the option range (with Β±2Β° tolerance). - **Buy YES**: Open-Meteo predicted temperature **falls within** the option range. ### Volume Detection - **High Volume**: Individual option volume β‰₯ $5,000. --- ## πŸ“’ Alerting Dimensions ### 1. πŸ“‚ City Alert Summaries (Push) - **Optimization**: All anomalies for the same city are merged into a **single report** per scan cycle to prevent spamming. - **Price Source**: Uses real **Ask price** (actual executable price), not mid price - **Push Format**: ``` πŸ“ Chicago Market Update πŸ• Local 08:30 | Forecast High:38Β°F ═══════════════════════ ✈️ Airport Obs (KORD): 🌑️ 32.0Β°F | Wind:12kt πŸ• Observed: 14:00 UTC ⚑ 40-41Β°F (2026-02-07): Buy No 87Β’ | Prediction:38Β°F [πŸ›’ $10.0 πŸ”₯High Conf] πŸ’‘ Strategy Tips: β€’ Predicted temp 38.0Β°F falls within 40-41Β°F range, market aligns with model ``` ### 2. ✈️ METAR Aviation Weather Data For same-day settlement markets, the system fetches **METAR airport observation data** and displays real measurements: ``` ✈️ Airport Obs (KORD): 🌑️ 12.0Β°F | Wind:15kt πŸ• Observed: 11:00 UTC ``` **ICAO Airport Code Mapping**: | City | ICAO | Airport | | ------------- | ---- | ---------------------------- | | Seattle | KSEA | Seattle-Tacoma International | | London | EGLC | London City Airport | | Dallas | KDAL | Dallas Love Field | | Miami | KMIA | Miami International | | Atlanta | KATL | Hartsfield-Jackson Atlanta | | Chicago | KORD | O'Hare International | | New York | KLGA | LaGuardia Airport | | Seoul | RKSI | Incheon International | | Ankara | LTAC | Esenboga Airport | | Toronto | CYYZ | Pearson International | | Wellington | NZWN | Wellington International | | Buenos Aires | SAEZ | Ministro Pistarini | **Data Source**: NOAA Aviation Weather Center (Free API, no key required) ### 3. ⚑ Price Alerts (Auto Paper Trade) - **Trigger**: Buy Yes or Buy No price enters the **85Β’-95Β’** range. - **Auto Action**: System executes a **$3-$10 Paper Trade** based on the dynamic position strategy. - **Purpose**: High-probability / Near-settlement reminders. ### 4. πŸ‘€ Market Anomalies - **Whale Inflow**: Large single trades (>$5,000) with imbalanced ratios. - **Volume Spikes**: Sudden increase in volume (>2x historical std dev). ### 5. πŸ“… Daily PnL Summary - **Trigger**: Triggered automatically around 23:55 (Beijing Time). - **Content**: Summarizes daily floating PnL, balance changes, and win rate. ### 6. 🎯 Trading Signals (`/signal`) Prioritizes markets with the **earliest settlement date**, sorted by opportunity value, returns **Top 5**: ``` 🎯 Upcoming Settlement (2026-02-06) 43 active options πŸ”₯ 1. Dallas 76-77Β°F πŸ’‘ Prediction 80.7Β° above 77Β° β†’ Buy NO βœ“ πŸ“Š Buy No 94Β’ | ⏳Near Lock πŸ”₯ 2. Atlanta 56-57Β°F πŸ’‘ Prediction 60.4Β° above 57Β° β†’ Buy NO βœ“ πŸ“Š Buy No 94Β’ | ⏳Near Lock ``` **Lock Status**: - πŸ”’Locked: Price β‰₯95Β’ - ⏳Near Lock: Price 85-94Β’ - πŸ‘€Watch: Price 70-84Β’ - βš–οΈBalanced: Price <70Β’ --- ## πŸ“Š Paper Trading Report Format Accessible via `/portfolio`. Reports are grouped by **Target Settlement Date**: ``` πŸ“Š Paper Trading Report ════════════════════ πŸ“ˆ 【2026-02-06】 Subtotal: +2.45$ ────────────────── 🟒 Chicago 40-41Β°F NO 87Β’β†’92Β’ Pred:38 | +0.47$ 🟒 Chicago 32-33Β°F NO 94Β’β†’98Β’ Pred:38 | +0.12$ πŸ’° Total Exposure PnL: +6.89$ πŸ“ˆ Historical Stats: Trades: 18 | Win Rate: 100.0% Total Cost: $90.00 | Total PnL: +12.50$ (+13.9%) ════════════════════ πŸ’³ Account Balance: $639.11 ``` --- ## πŸ› οΈ Configuration (.env) ```bash # Telegram Bot TELEGRAM_BOT_TOKEN=your_bot_token TELEGRAM_CHAT_ID=your_chat_id # Polymarket API (Used for real-time prices & trade history) POLYMARKET_API_KEY=your_api_key_here # Proxy (Optional, remove for VPS deployment) HTTPS_PROXY=http://127.0.0.1:7890 HTTP_PROXY=http://127.0.0.1:7890 ``` ## πŸ—οΈ Project Architecture This project is built on **py-clob-client** with REST API fallback: - Primary: Uses `py-clob-client` SDK for market data, orderbook, and trading - Fallback: Direct REST API calls (`/price`, `/book`) when SDK fails - Core API wrapper: `src/data_collection/polymarket_api.py` ### Price Fetching ```python # SDK method (primary) price = clob_client.get_price(token_id, side="BUY") # REST API fallback (when SDK fails) resp = requests.get("https://clob.polymarket.com/price", params={ "token_id": token_id, "side": "BUY" }) ``` ## πŸ“‚ Data Files | File | Description | | --------------------------- | ----------------------------------------------- | | `data/paper_positions.json` | Paper trading positions, balance, trade history | | `data/pushed_signals.json` | Pushed signals record (anti-spam) | | `data/active_signals.json` | Currently active trading signals | | `data/all_markets.json` | Full market cache | | `data/price_history.json` | Price history for trend calculation | --- ## πŸ“‹ Core Features - βœ… **Smart Dynamic Positions**: Automatic adjustment ($3-$10) based on weather forecasts, volume, and locking degree. - βœ… **Predicted Temp Tracking**: Records the Open-Meteo forecast at the time of purchase for retrospective analysis. - βœ… **Smart Merged Push**: City-based alert aggregation for a clean interface. - βœ… **Auto Paper Trading**: Built-in system for tracking performance within the 85-95Β’ range. - βœ… **High-Speed Price Sync**: Utilizes CLOB batch API for instant price updates without 404s. - βœ… **Timezone Adaptation**: All timestamps are automatically adjusted to Beijing Time (UTC+8). - βœ… **Smart Date Selection**: Automatically targets the earliest active market date. - βœ… **Unit Sensitivity**: US markets use Fahrenheit (Β°F), others use Celsius (Β°C). - βœ… **Data Persistence**: Local JSON storage ensures consistency after restarts. --- ## πŸ”„ VPS Update Instructions ```bash # 1. Local update git add . && git commit -m "update" && git push # 2. VPS pull & restart ssh root@VPS_IP "cd ~/PolyWeather && git pull && screen -S polyweather -X quit; screen -dmS polyweather python run.py" ```