Fixed GitGuardian security alert: - Removed hardcoded OpenRouter API key from POLYMARKET_QUICKSTART.md - Replaced with placeholder: sk-or-v1-YOUR_API_KEY_HERE - Also removed test wallet private key - Added instructions to generate own keys - .env file is properly gitignored (not committed) Users should: 1. Get their own OpenRouter API key from https://openrouter.ai/ 2. Generate their own wallet private key 3. Add to .env file (never commit .env)
10 KiB
๐ Polymarket Quick Start Guide
Get started with Polymarket prediction market trading in 10 minutes.
โก Super Quick Start (3 Commands)
# 1. Get testnet MATIC (takes 2 min)
# Visit: https://faucet.polygon.technology/
# Enter your address: 0xa5A4781aB598E841dc31F8437a3fef82278a0ee5
# 2. Run the live demo
npm run polymarket:demo
# 3. That's it! You're trading on Polymarket ๐
๐ Prerequisites (Already Done!)
โ Polymarket CLOB Client - Installed โ Multi-Chain Wallet - Configured โ Polygon Network - Set up โ AI Analysis - Ready (OpenRouter)
Your Wallet Address: 0xa5A4781aB598E841dc31F8437a3fef82278a0ee5
๐ฏ Step-by-Step Guide
Step 1: Get Polygon Testnet Tokens
MATIC (for gas fees):
- Visit: https://faucet.polygon.technology/
- Select "Mumbai Testnet"
- Paste address:
0xa5A4781aB598E841dc31F8437a3fef82278a0ee5 - Request 0.5 MATIC
- Wait 1-2 minutes
USDC (for trading) - OPTIONAL for demo:
- Visit: https://faucet.circle.com/
- Select "Polygon Mumbai"
- Request test USDC
- OR bridge from another testnet
Note: The demo works even without USDC - it will show you markets and let you analyze them!
Step 2: Run the Live Demo
npm run polymarket:demo
What the demo does:
- โ Checks your MATIC and USDC balances
- โ Fetches top 10 trending markets from Polymarket
- โ Analyzes the #1 market with AI
- โ Shows orderbook (bid/ask/spread)
- โ Displays your open positions
- โ Lists your active orders
Expected Output:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ POLYMARKET LIVE END-TO-END TRADING DEMO โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 1: CHECK WALLET BALANCES โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ MATIC Balance: 0.5000 MATIC
๐ต USDC Balance: $0.00 USDC
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 2: DISCOVER TRENDING MARKETS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Fetching active markets from Polymarket...
โ
Found 10 active markets
๐ Top 10 Markets by Volume:
1. Will Donald Trump win the 2024 election?
Volume: $50,234,567
Market ID: 0x123...
2. Will Bitcoin reach $100,000 by end of 2024?
Volume: $12,456,789
Market ID: 0x456...
... and more ...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STEP 3: AI MARKET ANALYSIS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ค Analyzing: Will Donald Trump win the 2024 election?
๐ Market Data:
Best Bid: 52.3%
Best Ask: 52.8%
Mid Price: 52.6%
Spread: 0.50%
Volume: $50,234,567
๐ง Running AI Analysis...
๐ก AI Analysis:
The market is highly liquid with a tight spread, suggesting efficient pricing.
The current probability of 52.6% reflects a very close race with high uncertainty.
I would recommend staying neutral and waiting for clearer signals.
โ
DEMO COMPLETE
Step 3: Place Your First Order (Optional)
If you have USDC, you can place real orders!
Modify the demo script:
// Add after Step 3 in polymarket-live-demo.ts
// Approve USDC (one-time setup)
await demo.approveUSDC('100'); // Approve $100 USDC
// Place a buy order
await demo.placeLimitOrder(
topMarket.condition_id,
'BUY',
0.50, // Buy at 50% probability
10 // $10 USDC size
);
// Check your order
await demo.getOpenOrders();
Then run:
npm run polymarket:demo
๐ Advanced Usage
Analyze Specific Markets
import { PolymarketLiveDemo } from './polymarket-live-demo';
const demo = new PolymarketLiveDemo(process.env.WALLET_PRIVATE_KEY!);
// Get all markets
const markets = await demo.discoverMarkets();
// Analyze each one
for (const market of markets) {
const analysis = await demo.analyzeMarket(market);
console.log(analysis);
}
Automated Trading Loop
// Run analysis every 5 minutes
setInterval(async () => {
const markets = await demo.discoverMarkets();
const analysis = await demo.analyzeMarket(markets[0]);
// If AI confidence > 80%, place order
if (analysis.aiAnalysis.includes('strong buy')) {
await demo.placeLimitOrder(
markets[0].condition_id,
'BUY',
analysis.bestAsk,
10
);
}
}, 5 * 60 * 1000);
Monitor Positions
// Check positions every minute
setInterval(async () => {
await demo.viewPositions();
await demo.getOpenOrders();
}, 60 * 1000);
๐ง Configuration
All settings are in .env:
# Enable/disable Polymarket
POLYMARKET_ENABLED=true
# Polymarket API
POLYMARKET_HOST=https://clob.polymarket.com
POLYMARKET_CHAIN_ID=137 # 137 = Polygon Mainnet, 80001 = Mumbai Testnet
# Polygon RPC
POLYGON_RPC=https://polygon-rpc.com
# Your wallet (generate your own!)
WALLET_PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
# AI Analysis (get your own from https://openrouter.ai/)
OPENROUTER_API_KEY=sk-or-v1-YOUR_API_KEY_HERE
๐ฐ Cost Estimate
Testnet (FREE!)
| Action | Gas (MATIC) | Cost |
|---|---|---|
| Approve USDC | ~0.0001 | $0.00 |
| Place Order | ~0.0003 | $0.00 |
| Cancel Order | ~0.00006 | $0.00 |
Total: All testnet tokens are free!
Mainnet (Real Money)
| Action | Gas (MATIC) | USD Cost |
|---|---|---|
| Approve USDC | ~0.0001 | ~$0.00009 |
| Place Order | ~0.0003 | ~$0.00027 |
| Cancel Order | ~0.00006 | ~$0.00005 |
Note: Polygon is 1000x cheaper than Ethereum!
๐ฏ Common Use Cases
1. Market Sentiment Analysis
# Run demo to see what markets are trending
npm run polymarket:demo
# AI will tell you if markets are fairly priced
2. Find Mispriced Markets
# The AI analyzer detects mispricing
# Look for markets where AI confidence is high but spread is wide
3. Hedge Crypto Positions
# If you're long BTC on DEX, hedge with:
# "Will Bitcoin crash?" prediction market
4. Event Arbitrage
# Find related markets with price discrepancies
# Example: "BTC > $100k" should be โค "BTC > $95k"
๐ Troubleshooting
"Insufficient MATIC for gas"
Solution:
# Get more MATIC from faucet
Visit: https://faucet.polygon.technology/
Address: 0xa5A4781aB598E841dc31F8437a3fef82278a0ee5
"No markets found"
Solution:
# Check internet connection
# Try different RPC endpoint in .env:
POLYGON_RPC=https://rpc-mainnet.maticvigil.com
"USDC approval failed"
Solution:
# Make sure you have USDC first
# Then run approval with higher gas:
await demo.approveUSDC('100');
"AI analysis not working"
Solution:
# Check OpenRouter API key in .env
OPENROUTER_API_KEY=sk-or-v1-YOUR_KEY_HERE
# Verify it's correct:
echo $OPENROUTER_API_KEY
๐ What Each File Does
| File | Purpose |
|---|---|
polymarket-live-demo.ts |
Main demo script - Run this! |
test-polymarket.ts |
Test suite - Verify integration |
src/polymarket/polymarketClient.ts |
Core client - Low-level API |
src/polymarket/marketDataFetcher.ts |
Market discovery - Find opportunities |
src/polymarket/aiPredictionAnalyzer.ts |
AI analysis - Smart decisions |
src/polymarket/crossPlatformStrategy.ts |
Multi-chain trading - Advanced strategies |
src/blockchain/multiChainWalletManager.ts |
Wallet management - Handle 3 chains |
๐ Learning Path
Day 1: Setup & Explore
- โ Get testnet MATIC
- โ
Run
npm run polymarket:demo - โ Explore trending markets
- โ Understand AI analysis
Day 2: First Trade
- Get testnet USDC
- Approve USDC spending
- Place first limit order
- Cancel and re-place
Day 3: Analysis
- Analyze 10+ markets
- Compare AI recommendations
- Track your accuracy
- Learn patterns
Week 2: Automation
- Build automated scanner
- Set up alerts
- Create trading bot
- Monitor performance
Month 1: Advanced
- Cross-platform arbitrage
- Correlation trading
- Hedging strategies
- Risk management
๐ Next Steps
Immediate (Today):
# 1. Get testnet MATIC (5 min)
https://faucet.polygon.technology/
# 2. Run demo (2 min)
npm run polymarket:demo
# 3. Read the AI analysis
# Understand how it evaluates markets
This Week:
- Get testnet USDC
- Place first test order
- Cancel an order
- Track a position
- Run automated analysis
This Month:
- Analyze 100+ markets
- Build trading strategy
- Test on mainnet (small amounts)
- Scale up gradually
๐ Additional Resources
- Full Documentation:
POLYMARKET_INTEGRATION.md - Test Suite:
npm run test:polymarket - Polymarket Docs: https://docs.polymarket.com/
- CLOB API: https://docs.polymarket.com/#clob-api
- Example Code:
polymarket-live-demo.ts
โ Quick Checklist
Before running the demo:
- Polymarket client installed
- Wallet configured in
.env - OpenRouter API key set
- Get testnet MATIC โ Do this now!
- Run
npm run polymarket:demo
๐ You're Ready!
Everything is set up. Just get testnet MATIC and run:
npm run polymarket:demo
Welcome to prediction market trading! ๐ฏ
Questions?
- Check
POLYMARKET_INTEGRATION.mdfor detailed docs - Run
npm run test:polymarketto test all features - Review example code in
polymarket-live-demo.ts
Happy Trading! ๐