Polymarket Configuration
This guide covers the specific setup required for Polymarket integration, including creating proxy contracts and configuring trading parameters.
Overview
PolyOracle AI integrates directly with Polymarket's APIs to:
- Fetch market data and orderbook information
- Place buy and sell orders
- Monitor positions and balances
- Execute trading strategies
Prerequisites
Before configuring Polymarket:
- Web3 wallet with Polygon network configured
- USDC on Polygon for trading
- Polymarket account with API access
Step 1: Create Polymarket Account
-
Visit Polymarket
- Go to polymarket.com
- Connect your Web3 wallet
-
Complete Account Setup
- Verify email if required
- Complete any KYC requirements
-
Generate API Keys
- Navigate to Account Settings → API
- Create new API key and secret
- Save these securely for your
.env
file
Step 2: Create Proxy Contract ⚡ Critical
The proxy contract is essential for the agent to trade on your behalf.
Manual Proxy Creation (Current Method)
-
Connect to Polymarket
- Visit polymarket.com
- Connect with your trading wallet (the one whose private key you'll use)
-
Trigger Proxy Creation
- Try to place any trade or interaction that requires the proxy
- Polymarket will prompt you to create the proxy contract
- Approve the transaction in your wallet
-
Find Your Proxy Address
- After creation, the proxy address will be displayed
- You can also find it in your wallet's transaction history
- Copy this address for configuration
Future: Automated Proxy Creation
The system is designed to support automatic proxy creation. To enable this:
# In backend/src/polyoracle/polymarket.py
# Change this line from:
self._init_approvals(False)
# To:
self._init_approvals(True)
⚠️ Note: This should only be run once and will create the proxy automatically when you first start make lg-server
.
Step 3: Configure Environment Variables
Add the following to your .env
files:
Backend Configuration
# Polymarket API
POLYMARKET_HOST=https://clob.polymarket.com
POLYMARKET_API_KEY=your_polymarket_api_key
POLYMARKET_API_SECRET=your_polymarket_secret
# Wallet Configuration
POLYGON_WALLET_PRIVATE_KEY=your_wallet_private_key
# Proxy Address (from Step 2)
NEXT_PUBLIC_POLYMARKET_PROXY_ADDRESS=0xYourProxyContractAddress
Frontend Configuration
# Proxy and Token Addresses
NEXT_PUBLIC_POLYMARKET_PROXY_ADDRESS=0xYourProxyContractAddress
NEXT_PUBLIC_USDCE_ADDRESS=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
Step 4: Fund Your Trading Wallet
-
Get USDC on Polygon
- Bridge USDC to Polygon network
- Or buy USDC directly on Polygon DEX
- Send to your trading wallet address
-
Minimum Recommended Balance
- Start with $100-500 USDC for testing
- Consider gas fees (small amounts of MATIC)
-
Verify Balance
# Test your setup
cd backend
make lg-server
# Check logs for wallet balance confirmation
Step 5: Test Polymarket Integration
Backend Testing
-
Start the Agent
cd backend
make lg-server -
Check Connection Logs Look for log messages confirming:
- ✅ Polymarket API connection successful
- ✅ Wallet balance loaded
- ✅ Proxy contract configured
-
Test Market Data The agent should be able to fetch market information without errors
Frontend Testing
-
Start Frontend
cd frontend
pnpm dev -
Connect Wallet
- Use the same wallet as your trading wallet
- Verify proxy address appears correctly
-
Test Market Analysis
- Try analyzing a market
- Verify data loads properly
Trading Configuration
Risk Settings
Configure trading parameters in the backend:
# In your agent configuration
MAX_POSITION_SIZE = 100 # Maximum USDC per trade
MIN_CONFIDENCE = 0.7 # Minimum confidence for trades
MAX_SPREAD = 0.05 # Maximum bid-ask spread to trade
Market Selection
The agent can be configured to trade specific types of markets:
# Market filters
MIN_VOLUME = 1000 # Minimum daily volume
MIN_LIQUIDITY = 5000 # Minimum total liquidity
MAX_TIME_TO_CLOSE = 30 # Maximum days until market close
Advanced Configuration
Custom Market Categories
Filter markets by category:
PREFERRED_CATEGORIES = [
"Politics",
"Economics",
"Sports",
"Crypto"
]
Research Depth Settings
Configure research intensity:
RESEARCH_CONFIG = {
"max_depth": 3, # Recursive research depth
"sources_per_query": 10, # Sources to analyze per query
"max_research_time": 300 # Max seconds for research phase
}
Security Considerations
Wallet Security
-
Dedicated Trading Wallet
- Create a separate wallet just for PolyOracle AI
- Never use your main wallet for automated trading
-
Private Key Storage
- Store private key securely in
.env
file - Use hardware wallet for key generation
- Regular key rotation for high-volume trading
- Store private key securely in
-
Position Limits
- Set maximum position sizes
- Implement daily trading limits
- Monitor unusual activity
API Security
-
API Key Permissions
- Use minimum required permissions
- Regularly rotate API keys
- Monitor API usage logs
-
Network Security
- Use secure connections only
- Consider VPN for additional security
- Monitor for unusual API calls
Troubleshooting Polymarket Issues
Common Connection Problems
"Invalid API credentials"
- Verify API key and secret are correct
- Check if API keys have necessary permissions
- Ensure no extra spaces in environment variables
"Proxy contract not found"
- Verify proxy address is correct
- Check if proxy was created for the right wallet
- Confirm proxy is deployed on Polygon network
"Insufficient balance"
- Check USDC balance in trading wallet
- Verify wallet has MATIC for gas fees
- Confirm funds are on Polygon network (not Ethereum)
Market Data Issues
"Market not found"
- Some markets may be delisted or closed
- Verify market ID format
- Check if market is still active
"Orderbook empty"
- Market may have low liquidity
- Try different markets for testing
- Check if market is near expiration
Trading Errors
"Order rejected"
- Check order size against available balance
- Verify order parameters are within limits
- Ensure market is still accepting orders
"Gas estimation failed"
- Increase gas limit in configuration
- Check MATIC balance for gas fees
- Verify network connectivity
Monitoring and Maintenance
Regular Checks
- Monitor wallet balance and positions
- Review trading performance metrics
- Check API usage and costs
- Verify proxy contract functionality
Performance Optimization
- Adjust research depth based on results
- Fine-tune confidence thresholds
- Optimize position sizing strategies
- Monitor and reduce API costs
Next Steps
After successful Polymarket configuration:
- Analyzing Markets - Learn how to analyze markets
- Trading Guide - Understand the trading process
- Performance Monitoring - Track your agent's performance
Need help with Polymarket issues? Check the Troubleshooting Guide for Polymarket-specific solutions.