Skip to main content

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

  1. Visit Polymarket

  2. Complete Account Setup

    • Verify email if required
    • Complete any KYC requirements
  3. 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)

  1. Connect to Polymarket

    • Visit polymarket.com
    • Connect with your trading wallet (the one whose private key you'll use)
  2. 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
  3. 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

  1. Get USDC on Polygon

    • Bridge USDC to Polygon network
    • Or buy USDC directly on Polygon DEX
    • Send to your trading wallet address
  2. Minimum Recommended Balance

    • Start with $100-500 USDC for testing
    • Consider gas fees (small amounts of MATIC)
  3. Verify Balance

    # Test your setup
    cd backend
    make lg-server
    # Check logs for wallet balance confirmation

Step 5: Test Polymarket Integration

Backend Testing

  1. Start the Agent

    cd backend
    make lg-server
  2. Check Connection Logs Look for log messages confirming:

    • ✅ Polymarket API connection successful
    • ✅ Wallet balance loaded
    • ✅ Proxy contract configured
  3. Test Market Data The agent should be able to fetch market information without errors

Frontend Testing

  1. Start Frontend

    cd frontend  
    pnpm dev
  2. Connect Wallet

    • Use the same wallet as your trading wallet
    • Verify proxy address appears correctly
  3. 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

  1. Dedicated Trading Wallet

    • Create a separate wallet just for PolyOracle AI
    • Never use your main wallet for automated trading
  2. Private Key Storage

    • Store private key securely in .env file
    • Use hardware wallet for key generation
    • Regular key rotation for high-volume trading
  3. Position Limits

    • Set maximum position sizes
    • Implement daily trading limits
    • Monitor unusual activity

API Security

  1. API Key Permissions

    • Use minimum required permissions
    • Regularly rotate API keys
    • Monitor API usage logs
  2. 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:

  1. Analyzing Markets - Learn how to analyze markets
  2. Trading Guide - Understand the trading process
  3. Performance Monitoring - Track your agent's performance

Need help with Polymarket issues? Check the Troubleshooting Guide for Polymarket-specific solutions.