Skip to main content

py-clob-client

PyPI

Python client for the Polymarket CLOB. Full API documentation can be found here.

Installation

pip install py-clob-client

Intended for use with Python 3.9

Requisites

Allowances

Adjusting and setting allowances is only required when using an EOA or a web3 wallet like MetaMask. If you sign in with a Magic link or email login, allowances are automatically configured for you during account creation.

If you are interacting with the API with an EOA or web3/MetaMask wallet then correct token allowances must be set before orders can be placed. The following mainnet (Polygon) allowances should be set by the funding (maker) address. For additional documentation please refer to the API documentation.

token(s) spender description
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E allow the CTF Exchange contract to transfer user's usdc
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 0xC5d563A36AE78145C45a50134d48A1215220f80a allow the Neg Risk CTF Exchange contract to transfer user's usdc
0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296 allow the Neg Risk Adapter contract to transfer user's usdc
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045 0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E allow the CTF Exchange contract to transfer user's conditional tokens
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045 0xC5d563A36AE78145C45a50134d48A1215220f80a allow the Neg Risk CTF Exchange contract to transfer user's conditional tokens
0x4D97DCd97eC945f40cF65F87097ACe5EA0476045 0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296 allow the Neg Risk Adapter contract to transfer user's conditional tokens

See this gist for a an example of how to set these allowances for an account using python.

Usage

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import OrderArgs, OrderType
from py_clob_client.order_builder.constants import BUY

host: str = "https://clob.polymarket.com"
key: str = "" #This is your Private Key. Export from reveal.polymarket.com or from your Web3 Application
chain_id: int = 137 #No need to adjust this
POLYMARKET_PROXY_ADDRESS: str = '' #This is the address you deposit/send USDC to to FUND your Polymarket account.

#Select from the following 3 initialization options to matches your login method, and remove any unused lines so only one client is initialized.


### Initialization of a client using a Polymarket Proxy associated with an Email/Magic account. If you login with your email use this example.
client = ClobClient(host, key=key, chain_id=chain_id, signature_type=1, funder=POLYMARKET_PROXY_ADDRESS)

### Initialization of a client using a Polymarket Proxy associated with a Browser Wallet(Metamask, Coinbase Wallet, etc)
client = ClobClient(host, key=key, chain_id=chain_id, signature_type=2, funder=POLYMARKET_PROXY_ADDRESS)

### Initialization of a client that trades directly from an EOA. 
client = ClobClient(host, key=key, chain_id=chain_id)

## Create and sign a limit order buying 5 tokens for 0.010c each
#Refer to the Markets API documentation to locate a tokenID: https://docs.polymarket.com/developers/gamma-markets-api/get-markets

client.set_api_creds(client.create_or_derive_api_creds()) 

order_args = OrderArgs(
    price=0.01,
    size=5.0,
    side=BUY,
    token_id="", #Token ID you want to purchase goes here. 
)
signed_order = client.create_order(order_args)

## GTC(Good-Till-Cancelled) Order
resp = client.post_order(signed_order, OrderType.GTC)
print(resp)

See examples for more.

Development

Install dependencies

make init

Tests

make fmt test

Publish

Ref: https://pythonpackaging.info/07-Package-Release.html

Installing the necessary libs
pip install twine setuptools
Compiling the code
python setup.py sdist
Checking the generated code and publish
twine check dist/*
# Checking dist/py_clob_client-0.22.0.tar.gz: PASSED
twine upload dist/*

# Uploading distributions to https://upload.pypi.org/legacy/
# Enter your API token:
# Uploading py_clob_client-0.22.0.tar.gz
# 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 31.9/31.9 kB • 00:00 • 29.6 MB/s

# View at:
# https://pypi.org/project/py-clob-client/0.22.0/

Metadata

Release files for tn-py-clob-client 0.23.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tn-py-clob-client 0.23.1
File Size Uploaded
tn_py_clob_client-0.23.1.tar.gz 25.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tn-py-clob-client 0.23.1
File Interpreter ABI Platform
tn_py_clob_client-0.23.1-py3-none-any.whl Python 3 none any Details

Total release size: 55.6 kB

Release files / tn_py_clob_client-0.23.1.tar.gz

Download URL tn_py_clob_client-0.23.1.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ed5ed1e8f3292d9ec9ac3816310b935335afd741c581c26675d854565a7c7528
BLAKE2b-256 checksum
How to use checksums
3cfeb57ca678359c62828b8528d8ab0363d4ce34fabe8af439f16e21d5dbd172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / tn_py_clob_client-0.23.1-py3-none-any.whl

Download URL tn_py_clob_client-0.23.1-py3-none-any.whl
Size 30.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d93f7143336c63db3b6f68abccfc33866a3a45c2bfdaf95e9c9f73d25b00bcc
BLAKE2b-256 checksum
How to use checksums
c5a60eb7c71f76ed81da5b37b91e0db3b00d735b31c8ef3f003515386dee3cb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.23.1 This release

2 release files

0.23.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page