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