Polymarket Agents

repository·main·Indexed 25 days ago

https://github.com/polymarket/agents

A developer framework and utility set for building autonomous AI agents that trade on Polymarket. It provides tools for RAG, data sourcing from news and web search, and integration with the Polymarket API. The framework includes a CLI for querying markets and events, LLM interaction for trading suggestions, and API connectors such as GammaMarketClient and Chroma DB for vectorizing data.

Tokens
1.4K
Snippets
6
Records
18
Agent score
85%

What's inside Polymarket Agents

  1. Install and set up Polymarket Agents

    main

    Polymarket Agents requires Python 3.9. Follow these steps to set up your local development environment:

    1. Clone the repository:

      git clone https://github.com/{username}/polymarket-agents.git
      cd polymarket-agents
    2. Create and activate a virtual environment:

      • On macOS/Linux:
        virtualenv --python=python3.9 .venv
        source .venv/bin/activate
      • On Windows:
        virtualenv --python=python3.9 .venv
        .venv\Scripts\activate
    3. Install dependencies:

      pip install -r requirements.txt
    4. Configure environment variables: Create a .env file in the project root by copying the example:

      cp .env.example .env

      Then, populate the following keys in .env:

      • `POLYGON_WALLET_PRIVATE_KEY=""
      • `OPENAI_API_KEY=""
    5. Prepare your wallet: Ensure your wallet is loaded with USDC.

    6. Set PYTHONPATH (if not using Docker): If running scripts directly from your local shell, set the following environment variable:

      export PYTHONPATH="."
    git clone https://github.com/{username}/polymarket-agents.git
    cd polymarket-agents
    virtualenv --python=python3.9 .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    cp .env.example .env
    export PYTHONPATH="."
  2. Run the Polymarket Agents CLI and Trading scripts

    main

    You can interact with the framework using the Command Line Interface (CLI) or by running the trading application directly.

    • To use the CLI:

      python scripts/python/cli.py
    • To run the trading agent:

      python agents/application/trade.py
    • To use Docker (alternative to local setup):

      ./scripts/bash/build-docker.sh
      ./scripts/bash/run-docker-dev.sh
    python scripts/python/cli.py
    # or
    python agents/application/trade.py
  3. Run the trading application example

    main

    To run the interactive trading agent demonstration, execute the trade.py script within a Python virtual environment. The agent follows a multi-step process: finding events, filtering markets, performing superforecaster-style probability analysis, and finally calculating a trade based on the difference between its predicted likelihood and current market prices.

    (.venv) $ python -i application/trade.py
  4. Reference the Polymarket Agents API connectors

    main

    The framework uses several connector modules to standardize data sources and market interactions:

    • Chroma.py: A Chroma DB implementation for vectorizing news sources and other API data. Supports custom vector database implementations.
    • Gamma.py: Contains the GammaMarketClient class for interfacing with the Polymarket Gamma API. Used to fetch and parse market and event metadata, including current and tradable markets.
    • Polymarket.py: Contains the Polymarket class for interacting with the Polymarket API. Handles API key initialization, market/event data retrieval, trade execution on the Polymarket DEX, and utility functions for building and signing orders.
    • Objects.py: Defines Pydantic data models for representing trades, markets, events, and related entities.
  5. Use the Polymarket Agents CLI commands

    main

    The cli.py script is the primary user interface. Commands follow this pattern: python scripts/python/cli.py command_name [attribute value] [attribute value]

    Example: get-all-markets

    Retrieves and displays a list of markets from Polymarket, sorted by volume.

    Usage:

    python scripts/python/cli.py get-all-markets --limit <LIMIT> --sort-by <SORT_BY>

    Arguments:

    • --limit: The number of markets to retrieve (default: 5).
    • --sort-by: The sorting criterion, either volume (default) or another valid attribute.
    python scripts/python/cli.py get-all-markets --limit <LIMIT> --sort-by <SORT_BY>