Polymarket CLI

repository·main·Indexed 25 days ago

https://github.com/polymarket/polymarket-cli

A Rust-based command-line interface for the Polymarket platform. It enables users and automated agents to browse markets, query the Central Limit Order Book (CLOB), place limit and market orders, and manage on-chain conditional tokens (CTF). The CLI supports JSON output for scripting, wallet management, and contract approvals for pUSD and CTF tokens.

Tokens
7.2K
Snippets
9
Records
79
Agent score
81%

What's inside polymarket-cli

  1. Install the Polymarket CLI

    main

    You can install the Polymarket CLI using Homebrew, a shell script, or by building from source using Cargo.

    ### Homebrew (macOS / Linux)
    
    ```bash
    brew tap Polymarket/polymarket-cli https://github.com/Polymarket/polymarket-cli
    brew install polymarket

    Shell script

    curl -sSL https://raw.githubusercontent.com/Polymarket/polymarket-cli/main/install.sh | sh

    Build from source

    git clone https://github.com/Polymarket/polymarket-cli
    cd polymarket-cli
    cargo install --path .
  2. Monitor your portfolio

    main

    Track your positions, total value, open orders, and trade history using the data and clob command groups. Replace 0xYOUR_ADDRESS with your actual wallet address.

    polymarket data positions 0xYOUR_ADDRESS
    polymarket data value 0xYOUR_ADDRESS
    polymarket clob orders
    polymarket clob trades
  3. Browse and research markets

    main

    Use the markets and clob command groups to search for markets, retrieve specific market details, view order books, and check price history. You can browse markets without a wallet configured.

    polymarket markets search "bitcoin" --limit 5
    polymarket markets get bitcoin-above-100k
    polymarket clob book 48331043336612883...
    polymarket clob price-history 48331043336612883... --interval 1d
  4. Configure the Polymarket CLI wallet

    main

    The CLI requires a private key to sign orders and on-chain transactions. It checks for credentials in this order:

    1. --private-key CLI flag
    2. POLYMARKET_PRIVATE_KEY environment variable
    3. ~/.config/polymarket/config.json configuration file.

    You can manage your wallet using the wallet command group.

    # Create a new wallet (generates random key, saves to config)
    polymarket wallet create
    
    # Import an existing key
    polymarket wallet import 0xabc123...
    
    # Check what's configured
    polymarket wallet show
  5. Set up a wallet and trade

    main

    To start trading, you must first create a wallet and approve it. Note that approve set requires MATIC for gas fees. Once set up, you can check your collateral balance and place market orders.

    polymarket wallet create
    polymarket approve set                    # needs MATIC for gas
    polymarket clob balance --asset-type collateral
    polymarket clob market-order --token TOKEN_ID --side buy --amount 5
  6. Place and manage limit orders

    main

    You can manage the lifecycle of limit orders by creating them, checking their status, and canceling individual or all orders.

    # Place order
    polymarket clob create-order --token TOKEN_ID --side buy --price 0.45 --size 20
    
    # Check it
    polymarket clob orders
    
    # Cancel if needed
    polymarket clob cancel ORDER_ID
    
    # Or cancel everything
    polymarket clob cancel-all
  7. Use JSON output for scripting

    main

    Use the -o json flag to output command results in JSON format. This is ideal for piping data into tools like jq or performing programmatic error handling in shell scripts.

    # Pipe market data to jq
    polymarket -o json markets list --limit 100 | jq '.[].question'
    
    # Check prices programmatically
    polymarket -o json clob midpoint TOKEN_ID | jq '.mid'
    
    # Error handling in scripts
    if ! result=$(polymarket -o json clob balance --asset-type collateral 2>/dev/null); then
      echo "Failed to fetch balance"
    fi
  8. Configure signature types

    main

    You can specify how transactions are signed using the --signature-type flag or the POLYMARKET_SIGNATURE_TYPE environment variable. Supported types are:

    • proxy (default): Uses Polymarket's proxy wallet system.
    • eoa: Signs directly with your key.
    • gnosis-safe: For multisig wallets.
  9. Derive and fund your proxy wallet

    main

    After setting up your main wallet, the CLI derives a proxy wallet address. This is the address you should use for trading.

    1. Proxy Address: The CLI will display your derived proxy address.
    2. Funding: Deposit pUSD to the proxy address. You can do this by running:
      polymarket bridge deposit <proxy_address>
      Or by transferring pUSD directly on the Polygon network.

    If proxy derivation fails, the CLI suggests using --signature-type eoa (depending on command availability).

  10. Configure a wallet via setup

    main

    When running the setup command, you will be prompted to choose between importing an existing private key or creating a new one.

    • Importing: Enter your existing private key when prompted. The CLI will validate it and save it to your local configuration.
    • Creating: If you choose not to use an existing key, the CLI generates a new LocalSigner on the POLYGON chain.

    Warning: If you create a new wallet, you must back up the private key from the generated config file. If lost, funds cannot be recovered.

  11. Run the setup command to configure your wallet

    main

    The setup command guides you through the initial configuration of the Polymarket CLI. It handles wallet creation or importation, derives a proxy wallet for trading, and provides instructions for funding and contract approval.

    The setup process includes:

    1. Wallet Configuration: Import an existing private key or generate a new one on the Polygon network.
    2. Proxy Wallet Derivation: Derives a proxy wallet address from your main address. You should deposit pUSD to this address to trade.
    3. Funding Instructions: Provides the address needed to deposit pUSD.
    4. Contract Approval: Reminds you to approve contracts for trading.

    Note: If proxy wallet derivation fails, you may need to use the --signature-type eoa flag (if available in the command context).