Skip to main content

Python client for the Polymarket CLOBV2

Project description

[!NOTE] We've released a new unified SDK that combines all our REST APIs and WebSockets into one package. We recommend Polymarket/py-sdk for new projects.

PY Polymarket CLOB Client V2

Python client for the Polymarket CLOB (v2)

Usage

# pip install py_clob_client_v2

import os
from py_clob_client_v2 import ApiCreds, ClobClient, OrderArgs, OrderType, PartialCreateOrderOptions, Side

host = "<polymarket-clob-host>"
chain_id = 137  # or 80002 for Amoy testnet

# Step 1: obtain API credentials using your wallet (L1 auth)
client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"])
creds = client.create_or_derive_api_key()

# Step 2: initialize a fully-authenticated client (L1 + L2)
client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"], creds=creds)

# Place a resting limit buy (GTC)
resp = client.create_and_post_order(
    order_args=OrderArgs(
        token_id="",  # token ID of the market outcome — get from https://docs.polymarket.com
        price=0.4,
        side=Side.BUY,
        size=100,
    ),
    options=PartialCreateOrderOptions(tick_size="0.01"),
    order_type=OrderType.GTC,
)
print(resp)

See examples for more information.

Market Orders

from py_clob_client_v2 import MarketOrderArgs

# Market buy — amount is in USDC
# OrderType.FOK: entire order must fill immediately or it is cancelled
# OrderType.FAK: fills as much as possible, remainder is cancelled
resp = client.create_and_post_market_order(
    order_args=MarketOrderArgs(
        token_id="",
        amount=100,  # USDC
        side=Side.BUY,
        order_type=OrderType.FOK,
    ),
    options=PartialCreateOrderOptions(tick_size="0.01"),
    order_type=OrderType.FOK,
)
print(resp)

Authentication

The client has two authentication levels:

L1 — wallet signature (EIP-712). Required to create or derive API keys.

client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"])
creds = client.create_or_derive_api_key()

L2 — HMAC with API credentials. Required for order placement, cancellation, and account data.

creds = ApiCreds(
    api_key=os.environ["CLOB_API_KEY"],
    api_secret=os.environ["CLOB_SECRET"],
    api_passphrase=os.environ["CLOB_PASS_PHRASE"],
)
client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"], creds=creds)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_clob_client_v2-1.0.2.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_clob_client_v2-1.0.2-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file py_clob_client_v2-1.0.2.tar.gz.

File metadata

  • Download URL: py_clob_client_v2-1.0.2.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_clob_client_v2-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9c19a86a1ca67a995f3da4f2d95fd5d5e9e7e14777cb6fe4294b90040ccf67d0
MD5 d1c0a526c41f2b65b2610cad5e13b493
BLAKE2b-256 53de7d5c9e02988a221c44ab2d74b4bd682810e3e3f3a4856be7eef2bc874f6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_clob_client_v2-1.0.2.tar.gz:

Publisher: release.yaml on Polymarket/py-clob-client-v2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_clob_client_v2-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for py_clob_client_v2-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca0b15016c3850ebafd702c0ffea134b4779878289590922a6ac43045cd3486a
MD5 f99df824796a7cb6405c425d6ab8f51b
BLAKE2b-256 2bb92a72a6da948ab7df4b27335d515a1ebd061b8b1b855813af8c6202506b21

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_clob_client_v2-1.0.2-py3-none-any.whl:

Publisher: release.yaml on Polymarket/py-clob-client-v2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page