Skip to content

VirilePeak/agents

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Debug endpoints

To enable debug/admin endpoints (only for trusted networks), set:

DEBUG_ENDPOINTS_ENABLED=1
# optional:
DEBUG_ENDPOINTS_TOKEN=your-secret-token

The subscriptions view requires the X-Debug-Token header when DEBUG_ENDPOINTS_TOKEN is set.

BTC Up/Down timeframe (15m / 5m)

Default: 15 minutes.

Enable 5-minute markets via env:

  • BTC_UPDOWN_TIMEFRAME_MINUTES=5
  • optional safety toggle: BTC_UPDOWN_ENABLE_5M=1

Timing guards (recommended defaults already set in src/config/settings.py):

  • BTC_UPDOWN_ENTRY_DEADLINE_SECONDS (only enter early in the window)
  • BTC_UPDOWN_MIN_TIME_TO_END_SECONDS (do not enter too close to window end)
  • BTC_UPDOWN_AUTO_CLOSE_BUFFER_SECONDS (auto-close shortly before window end)

Example:

export BTC_UPDOWN_TIMEFRAME_MINUTES=5
export BTC_UPDOWN_ENABLE_5M=1

Contributors Forks Stargazers Issues MIT License


Logo

Polymarket Agents

Trade autonomously on Polymarket using AI Agents
Explore the docs »

View Demo · Report Bug · Request Feature

Polymarket Agents

Polymarket Agents is a developer framework and set of utilities for building AI agents for Polymarket.

This code is free and publicly available under MIT License open source license (terms of service)!

Features

  • Integration with Polymarket API
  • AI agent utilities for prediction markets
  • Local and remote RAG (Retrieval-Augmented Generation) support
  • Data sourcing from betting services, news providers, and web search
  • Comphrehensive LLM tools for prompt engineering

Getting started

This repo is inteded for use with Python 3.9

  1. Clone the repository

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

    virtualenv --python=python3.9 .venv
    
  3. Activate the virtual environment

    • On Windows:
    .venv\Scripts\activate
    
    • On macOS and Linux:
    source .venv/bin/activate
    
  4. Install the required dependencies:

    pip install -r requirements.txt
    
  5. Set up your environment variables:

    • Create a .env file in the project root directory
    cp .env.example .env
    
    • Add the following environment variables:
    POLYGON_WALLET_PRIVATE_KEY=""
    OPENAI_API_KEY=""
    
  6. Load your wallet with USDC.

  7. Try the command line interface...

    python scripts/python/cli.py
    

    Or just go trade!

    python agents/application/trade.py
    
  8. Note: If running the command outside of docker, please set the following env var:

    export PYTHONPATH="."
    

    If running with docker is preferred, we provide the following scripts:

    ./scripts/bash/build-docker.sh
    ./scripts/bash/run-docker-dev.sh
    

Trading bot safety & verification

Required environment variables

Use environment variables for credentials and never commit secrets to git:

  • POLYGON_WALLET_PRIVATE_KEY
  • OPENAI_API_KEY
  • CLOB_API_KEY / CLOB_SECRET (if live CLOB auth is used)

Use .env.example as template and keep .env local only.

Feature flags (safe defaults)

Core optional runtime paths are feature-flagged and should remain disabled unless explicitly testing:

  • MARKET_DATA_WS_ENABLED=0 (disable WS stream; default flow keeps running via existing path)
  • MARKET_DATA_RTDS_ENABLED=0 (disable RTDS stream)
  • DEBUG_ENDPOINTS_ENABLED=0 (disable admin/debug endpoints)

Boolean env values are parsed robustly (0/1, true/false, yes/no).

Verification commands

Run these checks locally before deploying:

pytest -q
curl -s http://127.0.0.1:5000/market-data/metrics
curl -s http://127.0.0.1:5000/market-data/health

For a default safety smoke test, run with flags off:

export MARKET_DATA_WS_ENABLED=0
export MARKET_DATA_RTDS_ENABLED=0
python agents/application/trade.py

Health endpoint semantics (/market-data/health)

/market-data/health is a trading-readiness health, not just process liveness:

  • ok=true means market-data path is considered ready for trading decisions.
  • ok=false can be expected in offline/dev scenarios (e.g., no live WS traffic yet), even when the app process is stable.
  • ws_connected indicates websocket connectivity status.
  • last_msg_age_s indicates freshness of most recent market-data message.
  • active_subscriptions indicates current adapter subscription count.

For operational monitoring, treat API reachability + /market-data/metrics availability as process-level health, and /market-data/health.ok as readiness-to-trade.

Architecture

The Polymarket Agents architecture features modular components that can be maintained and extended by individual community members.

APIs

Polymarket Agents connectors standardize data sources and order types.

  • Chroma.py: chroma DB for vectorizing news sources and other API data. Developers are able to add their own vector database implementations.

  • Gamma.py: defines GammaMarketClient class, which interfaces with the Polymarket Gamma API to fetch and parse market and event metadata. Methods to retrieve current and tradable markets, as well as defined information on specific markets and events.

  • Polymarket.py: defines a Polymarket class that interacts with the Polymarket API to retrieve and manage market and event data, and to execute orders on the Polymarket DEX. It includes methods for API key initialization, market and event data retrieval, and trade execution. The file also provides utility functions for building and signing orders, as well as examples for testing API interactions.

  • Objects.py: data models using Pydantic; representations for trades, markets, events, and related entities.

Scripts

Files for managing your local environment, server set-up to run the application remotely, and cli for end-user commands.

cli.py is the primary user interface for the repo. Users can run various commands to interact with the Polymarket API, retrieve relevant news articles, query local data, send data/prompts to LLMs, and execute trades in Polymarkets.

Commands should follow this format:

python scripts/python/cli.py command_name [attribute value] [attribute value]

Example:

get-all-markets Retrieve and display a list of markets from Polymarket, sorted by volume.

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

Contributing

If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes.
  4. Submit a pull request.

Please run pre-commit hooks before making contributions. To initialize them:

pre-commit install

Related Repos

Prediction markets reading

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For any questions or inquiries, please contact liam@polymarket.com or reach out at www.greenestreet.xyz

Enjoy using the CLI application! If you encounter any issues, feel free to open an issue on the repository.

Terms of Service

Terms of Service prohibit US persons and persons from certain other jurisdictions from trading on Polymarket (via UI & API and including agents developed by persons in restricted jurisdictions), although data and information is viewable globally.

About

Trade autonomously on Polymarket using AI Agents

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 98.2%
  • Other 1.8%