market-notes.mp4
A Chrome extension that integrates Polymarket prediction market trading directly into X (Twitter), featuring real-time market data, live trading capabilities, and user position tracking. Community Notes meet Prediction Markets: https://devpost.com/software/market-note.
polymarket-trading-extension/
├── extension/ # Chrome Extension Files
│ ├── manifest.json # Extension manifest
│ ├── content.js # Main extension logic (55KB)
│ ├── background.js # Background service worker
│ ├── styles.css # Extension styling
│ └── icons/ # Extension icons
├── backend/ # Flask Trading Backend
│ ├── trading_backend.py # Main Flask API server
│ ├── requirements.txt # Python dependencies
| ├── tweet-market-pipeline/ # Pipeline for processing tweets into markets
│ └── data/ # Sample Market Data
│ ├── samplein.json # Single market sample
│ ├── samplemultimarkets.json # Multi-market sample
│ └── sampleoneopenposition.json # Position sample
├── scripts/ # Utility Scripts
│ └── start_trading.sh # Startup script
├── .env # Environment variables (Magic wallet keys)
├── .gitignore
└── README.md
- Smart Market Discovery: Automatically analyzes tweet content to find relevant Polymarket events
- Cohere AI Integration: Uses advanced NLP to understand tweet context and sentiment
- Polymarket Search: Searches live Polymarket API for active, tradeable markets
- Relevance Ranking: AI ranks markets by relevance to the specific tweet content
- Fallback Support: Falls back to sample data if tweet analysis fails
- AI-Generated Events: Shows AI-discovered markets relevant to the tweet
- Navigation Controls: Use ← → arrows to browse through discovered markets
- Event Counter: Shows current position (e.g., "3 / 6" events)
- Mixed Market Types: Supports both single-market and multi-candidate events
- YES/NO Trading: Click buttons to select position and see real-time pricing
- Live Calculations: Profit/payout updates as you type dollar amounts
- Smart Formatting: Automatic $ formatting with decimal validation
- Execute Trades: Direct integration with Polymarket API for real trading
- Candidate Cards: Visual cards for multi-candidate markets (e.g., NYC Mayor race)
- Probability Display: Shows percentage odds (handles <1% edge case)
- Click to Trade: Expand any candidate to show trading interface
- Volume & Images: Candidate photos and trading volume per market
- Live Positions: Real positions from your Polymarket account via API
- Open/Closed Tabs: Switch between active and closed positions
- P&L Tracking: Color-coded profit/loss with detailed breakdowns
- Position Details: Shares, average price, current price, total value
# Run from project root
./scripts/start_trading.shCreate .env file in project root:
# Required for trading
magickey=your_magic_wallet_private_key
funder=your_polymarket_wallet_address
# Required for AI tweet analysis
COHERE_API_KEY=your_cohere_api_keyGet API keys:
- Magic wallet keys: From your Polymarket account settings
- Cohere API key: From Cohere Dashboard
- Open Chrome → Extensions → Developer mode
- Click "Load unpacked"
- Select the
extension/folder - Extension icon should appear in toolbar
- Content Script: Injects trading UI into Twitter pages
- Background Worker: Handles CORS-restricted API calls to localhost
- Messaging: Chrome runtime messaging between content/background scripts
- CORS Enabled: Allows requests from Chrome extension
- Magic Wallet: Uses py-clob-client with Magic wallet authentication
- Real Trading: Connects to Polymarket CLOB API for live trading
- Sample Data: Falls back to JSON files when API unavailable
Twitter Page → Extract Tweet Text → AI Analysis Pipeline → Relevant Markets
↓ ↓ ↓ ↓
Content Script → Background Script → Flask API → Cohere + Polymarket APIs
↓
Trading Interface with AI-Discovered Markets
- Open X (Twitter) in Chrome
- Look for Polymarket icon next to other tweet buttons
- Click button on any tweet - AI will analyze the content
- View AI-discovered markets relevant to the tweet
- Use ← → arrows to navigate between discovered events
- Click YES/NO, enter amount, execute trades on relevant markets
- Visit any Twitter profile page
- Positions section appears above tweet tabs
- Toggle between Open/Closed positions
- View real P&L and position details
- Live API: Real-time data from Polymarket CLOB API
- Sample Data: JSON files in
backend/data/for development - Fallback Logic: Gracefully handles API failures
- Environment Variables: Sensitive keys stored in
.env - No Key Exposure: Private keys never sent to frontend
- Magic Wallet: Secure wallet integration via py-clob-client
- CORS Protection: Backend only accepts requests from extension
./scripts/start_trading.sh- Navigate to
chrome://extensions/ - Enable "Developer mode"
- Click "Load unpacked" → select
extension/folder
GET /api/market- Single market dataGET /api/events- Multiple events for carouselPOST /api/analyze-tweet- NEW: AI-powered tweet analysisGET /api/positions- User's open positionsGET /api/closed-positions- User's closed positionsPOST /api/trade- Execute trades
- 🧠 AI-Powered Tweet Analysis: Automatically discovers relevant markets for any tweet
- 🤖 Cohere Integration: Advanced NLP for tweet sentiment and context analysis
- 🔍 Smart Market Search: Live Polymarket API search with AI relevance ranking
- 🎯 Context-Aware Trading: Show only markets relevant to the specific tweet
- 📊 Pipeline Integration: Complete tweet-to-market analysis pipeline
- Position API Integration: Real position data from Polymarket
- UI/UX Improvements: Better button highlighting, profit calculations
- Code Cleanup: Organized file structure, removed test files
Built with Flask, Chrome Extensions API, Polymarket CLOB API, and Cohere AI