Skip to main content

Wayfinder fork of the Polymarket CLOBV2 Python client

Project description

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_wayfinder-1.0.1.tar.gz (44.5 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_wayfinder-1.0.1-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

Details for the file py_clob_client_v2_wayfinder-1.0.1.tar.gz.

File metadata

File hashes

Hashes for py_clob_client_v2_wayfinder-1.0.1.tar.gz
Algorithm Hash digest
SHA256 aa413ac42138755931dfbd5da45c977ad245f339c5a30463407993bf69323ec8
MD5 5f7866b20d7a4ba6b25f589daab0026f
BLAKE2b-256 ddb33a86794558242c5ff2c7fc126f50eb1968f5411f6904618a69edc8fc2e63

See more details on using hashes here.

File details

Details for the file py_clob_client_v2_wayfinder-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_clob_client_v2_wayfinder-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32842cb11038182ff78b31de5a4861eab9d8ec55647590ff8377b061767da4ac
MD5 5a9679622ad7965a9649cc6b29bab102
BLAKE2b-256 7281005d0f245790b6cbefdc4ae361acc94e2cb18ff1832e7e9d8cd5298ab0a5

See more details on using hashes here.

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