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)
455 lines
10 KiB
Markdown
455 lines
10 KiB
Markdown
# ๐ Polymarket Quick Start Guide
|
|
|
|
Get started with Polymarket prediction market trading in **10 minutes**.
|
|
|
|
---
|
|
|
|
## โก Super Quick Start (3 Commands)
|
|
|
|
```bash
|
|
# 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):**
|
|
|
|
1. Visit: https://faucet.polygon.technology/
|
|
2. Select "Mumbai Testnet"
|
|
3. Paste address: `0xa5A4781aB598E841dc31F8437a3fef82278a0ee5`
|
|
4. Request 0.5 MATIC
|
|
5. Wait 1-2 minutes
|
|
|
|
**USDC (for trading) - OPTIONAL for demo:**
|
|
|
|
1. Visit: https://faucet.circle.com/
|
|
2. Select "Polygon Mumbai"
|
|
3. Request test USDC
|
|
4. 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
|
|
|
|
```bash
|
|
npm run polymarket:demo
|
|
```
|
|
|
|
**What the demo does:**
|
|
|
|
1. โ
Checks your MATIC and USDC balances
|
|
2. โ
Fetches top 10 trending markets from Polymarket
|
|
3. โ
Analyzes the #1 market with AI
|
|
4. โ
Shows orderbook (bid/ask/spread)
|
|
5. โ
Displays your open positions
|
|
6. โ
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:**
|
|
|
|
```typescript
|
|
// 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:
|
|
```bash
|
|
npm run polymarket:demo
|
|
```
|
|
|
|
---
|
|
|
|
## ๐ Advanced Usage
|
|
|
|
### Analyze Specific Markets
|
|
|
|
```typescript
|
|
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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
// Check positions every minute
|
|
setInterval(async () => {
|
|
await demo.viewPositions();
|
|
await demo.getOpenOrders();
|
|
}, 60 * 1000);
|
|
```
|
|
|
|
---
|
|
|
|
## ๐ง Configuration
|
|
|
|
All settings are in `.env`:
|
|
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# The AI analyzer detects mispricing
|
|
# Look for markets where AI confidence is high but spread is wide
|
|
```
|
|
|
|
### 3. Hedge Crypto Positions
|
|
|
|
```bash
|
|
# If you're long BTC on DEX, hedge with:
|
|
# "Will Bitcoin crash?" prediction market
|
|
```
|
|
|
|
### 4. Event Arbitrage
|
|
|
|
```bash
|
|
# Find related markets with price discrepancies
|
|
# Example: "BTC > $100k" should be โค "BTC > $95k"
|
|
```
|
|
|
|
---
|
|
|
|
## ๐ Troubleshooting
|
|
|
|
### "Insufficient MATIC for gas"
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Get more MATIC from faucet
|
|
Visit: https://faucet.polygon.technology/
|
|
Address: 0xa5A4781aB598E841dc31F8437a3fef82278a0ee5
|
|
```
|
|
|
|
### "No markets found"
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Check internet connection
|
|
# Try different RPC endpoint in .env:
|
|
POLYGON_RPC=https://rpc-mainnet.maticvigil.com
|
|
```
|
|
|
|
### "USDC approval failed"
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Make sure you have USDC first
|
|
# Then run approval with higher gas:
|
|
await demo.approveUSDC('100');
|
|
```
|
|
|
|
### "AI analysis not working"
|
|
|
|
**Solution:**
|
|
```bash
|
|
# 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
|
|
1. โ
Get testnet MATIC
|
|
2. โ
Run `npm run polymarket:demo`
|
|
3. โ
Explore trending markets
|
|
4. โ
Understand AI analysis
|
|
|
|
### Day 2: First Trade
|
|
1. Get testnet USDC
|
|
2. Approve USDC spending
|
|
3. Place first limit order
|
|
4. Cancel and re-place
|
|
|
|
### Day 3: Analysis
|
|
1. Analyze 10+ markets
|
|
2. Compare AI recommendations
|
|
3. Track your accuracy
|
|
4. Learn patterns
|
|
|
|
### Week 2: Automation
|
|
1. Build automated scanner
|
|
2. Set up alerts
|
|
3. Create trading bot
|
|
4. Monitor performance
|
|
|
|
### Month 1: Advanced
|
|
1. Cross-platform arbitrage
|
|
2. Correlation trading
|
|
3. Hedging strategies
|
|
4. Risk management
|
|
|
|
---
|
|
|
|
## ๐ Next Steps
|
|
|
|
### Immediate (Today):
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
- [x] Polymarket client installed
|
|
- [x] Wallet configured in `.env`
|
|
- [x] 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:
|
|
|
|
```bash
|
|
npm run polymarket:demo
|
|
```
|
|
|
|
**Welcome to prediction market trading!** ๐ฏ
|
|
|
|
---
|
|
|
|
**Questions?**
|
|
- Check `POLYMARKET_INTEGRATION.md` for detailed docs
|
|
- Run `npm run test:polymarket` to test all features
|
|
- Review example code in `polymarket-live-demo.ts`
|
|
|
|
**Happy Trading!** ๐
|