Trade autonomously on Polymarket using AI Agents
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
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)!
This repo is inteded for use with Python 3.9
Clone the repository
git clone https://github.com/{username}/polymarket-agents.git
cd polymarket-agents
Create the virtual environment
virtualenv --python=python3.9 .venv
Activate the virtual environment
.venv\Scripts\activate
source .venv/bin/activate
Install the required dependencies:
pip install -r requirements.txt
Set up your environment variables:
.env
file in the project root directorycp .env.example .env
POLYGON_WALLET_PRIVATE_KEY=""
OPENAI_API_KEY=""
Load your wallet with USDC.
Try the command line interface...
python scripts/python/cli.py
Or just go trade!
python agents/application/trade.py
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
The Polymarket Agents architecture features modular components that can be maintained and extended by individual community members.
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.
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>
If you would like to contribute to this project, please follow these steps:
Please run pre-commit hooks before making contributions. To initialize them:
pre-commit install
This project is licensed under the MIT License. See the LICENSE file for details.
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 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.