Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Python client for the Polymarket CLOB (v2)

## Environment Setup

Before running the examples or initializing the client, ensure you have set up your environment variables. You can copy the provided example file to get started:

```bash
cp .env.example .env
```

Then, populate your new `.env` file with your credentials:
- `PK`: Your wallet's private key (Required for L1 auth).
- `CLOB_API_KEY`, `CLOB_SECRET`, `CLOB_PASS_PHRASE`: Your API credentials (Required for L2 auth).

### Usage

```python
Expand All @@ -23,7 +35,7 @@ client = ClobClient(host=host, chain_id=chain_id, key=os.environ["PK"], creds=cr
# 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
token_id="", # token ID of the market outcome — get from [https://docs.polymarket.com](https://docs.polymarket.com)
price=0.4,
side=Side.BUY,
size=100,
Expand Down
7 changes: 7 additions & 0 deletions examples/orders/cancel_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@


def main():
# Load the private key from the environment
pk = os.environ["PK"]
account = Account.from_key(pk)

# Default to Mumbai testnet (80002) if no chain ID is provided
chain_id = int(os.environ.get("CHAIN_ID", 80002))
print(f"Address: {account.address}, chainId: {chain_id}")

# Initialize the ClobClient with API credentials
host = os.environ.get("CLOB_API_URL", "http://localhost:8080")
creds = ApiCreds(
api_key=os.environ["CLOB_API_KEY"],
Expand All @@ -21,9 +25,12 @@ def main():
)
client = ClobClient(host=host, chain_id=chain_id, key=pk, creds=creds)

# Cancel one or multiple existing orders by their Order IDs
# Note: Replace the example string below with your actual order ID(s)
resp = client.cancel_orders([
"0x7ce769d075f4f1263603fde09862f5998f5e6ae4a39a16f3780f0bd708d3fc1c",
])

print(resp)
print("Done!")

Expand Down