// Polymarket CLI for AI Agents

Released Feb 24, 2026 | Built with Rust | Official Polymarket tool

What is Polymarket CLI?
Official command-line interface for Polymarket prediction markets. Query markets, place orders, manage positions—all from terminal or as JSON API for agents.

// Installation

Option 1: Cargo (Recommended)

# Requires Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install CLI
cargo install polymarket-cli

# Verify
polymarket --version

Option 2: Build from Source

git clone https://github.com/Polymarket/polymarket-cli
cd polymarket-cli
cargo build --release

# Binary at ./target/release/polymarket

// Wallet Setup

Polymarket runs on Polygon. You need a funded wallet to place orders.

# Create new wallet (saves to ~/.polymarket/wallet.json)
polymarket wallet create

# Or import existing
polymarket wallet import --private-key YOUR_PRIVATE_KEY

# Check balance
polymarket wallet balance
Security: Private keys are stored locally. Use a dedicated wallet for trading, not your main holdings.

Fund Your Wallet

  1. Get MATIC for gas (Polygon network)
  2. Get USDC for trading (Polymarket uses USDC)
  3. Bridge from Ethereum if needed: Polygon Bridge

// Querying Markets

List All Markets

# Get active markets
polymarket markets list

# Filter by category
polymarket markets list --category sports
polymarket markets list --category crypto
polymarket markets list --category politics

# JSON output (for agents)
polymarket markets list --output json

Get Market Details

# Get specific market
polymarket market get 0x1234...

# Output
{
  "id": "0x1234...",
  "question": "Will Team Liquid win ESL Pro League?",
  "outcomes": ["Yes", "No"],
  "prices": {
    "yes": 0.65,
    "no": 0.37
  },
  "volume": 125000,
  "liquidity": 50000,
  "endDate": "2026-03-15T00:00:00Z"
}

Search Markets

# Search by keyword
polymarket markets search "esports"
polymarket markets search "CS2"
polymarket markets search "League of Legends"

// Placing Orders

Market Order

# Buy YES shares
polymarket order market --market 0x1234... --side yes --amount 100

# Buy NO shares
polymarket order market --market 0x1234... --side no --amount 50

Limit Order

# Buy YES at specific price
polymarket order limit --market 0x1234... --side yes --amount 100 --price 0.55

# Sell existing position
polymarket order limit --market 0x1234... --side yes --amount 50 --price 0.70 --sell

Check Orders

# View open orders
polymarket orders list

# Cancel order
polymarket order cancel ORDER_ID

// Positions & Portfolio

# View all positions
polymarket positions

# Output
{
  "positions": [
    {
      "market": "0x1234...",
      "question": "Will Team Liquid win ESL Pro League?",
      "side": "yes",
      "shares": 150,
      "avgPrice": 0.58,
      "currentPrice": 0.65,
      "pnl": "+$10.50",
      "pnlPercent": "+12.1%"
    }
  ],
  "totalValue": 97.50,
  "totalPnl": 10.50
}

// Agent Integration

For autonomous agents, use JSON output mode and pipe to your decision engine:

#!/bin/bash
# Example: Monitor market and alert on price changes

MARKET="0x1234..."
THRESHOLD=0.70

while true; do
  PRICE=$(polymarket market get $MARKET --output json | jq '.prices.yes')
  
  if (( $(echo "$PRICE > $THRESHOLD" | bc -l) )); then
    echo "ALERT: Price above threshold: $PRICE"
    # Trigger your agent's sell logic
  fi
  
  sleep 60
done

Python Integration

import subprocess
import json

def get_market(market_id):
    result = subprocess.run(
        ["polymarket", "market", "get", market_id, "--output", "json"],
        capture_output=True, text=True
    )
    return json.loads(result.stdout)

def place_order(market_id, side, amount, price=None):
    cmd = ["polymarket", "order"]
    if price:
        cmd.extend(["limit", "--price", str(price)])
    else:
        cmd.append("market")
    
    cmd.extend([
        "--market", market_id,
        "--side", side,
        "--amount", str(amount)
    ])
    
    result = subprocess.run(cmd, capture_output=True, text=True)
    return json.loads(result.stdout)

# Usage
market = get_market("0x1234...")
if market["prices"]["yes"] < 0.50:
    place_order("0x1234...", "yes", 100)

// Also See: Polymarket Agents SDK

For more sophisticated autonomous trading, Polymarket also offers a Python SDK specifically for AI agents:

# Install
pip install polymarket-agents

# Clone examples
git clone https://github.com/Polymarket/agents
cd agents

The Agents SDK connects to LLMs for market analysis and automated decision-making. View on GitHub →

// Command Reference

Command Description
polymarket markets list List all active markets
polymarket market get ID Get market details
polymarket markets search QUERY Search markets
polymarket order market Place market order
polymarket order limit Place limit order
polymarket orders list View open orders
polymarket positions View portfolio
polymarket wallet balance Check wallet balance