Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -266,8 +266,20 @@ See [this Python example](https://gist.github.com/poly-rodr/44313920481de58d5a3f

**Pro tip**: You only need to set these once per wallet. After that, you can trade freely.

## Examples

The `examples/` directory contains minimal Python scripts demonstrating common
CLOB workflows:

- `fetch_markets.py` – fetch active markets
- `get_orderbook.py` – fetch a single orderbook by token_id
- `get_orderbooks.py` – fetch multiple orderbooks in one request
- `get_orders.py` – fetch open orders for a market (requires API credentials)

These scripts are intentionally minimal and designed for quick experimentation.

## Notes
- To discover token IDs, use the Markets API Explorer: [Get Markets](https://docs.polymarket.com/developers/gamma-markets-api/get-markets).
- Prices are in dollars from 0.00 to 1.00. Shares are whole or fractional units of the outcome token.

See [/example](/examples) for more.
See [/example](/examples) for more.
22 changes: 22 additions & 0 deletions examples/fetch_markets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Minimal example: Fetch active Polymarket markets
"""

from polymarket.client import ClobClient


def main():
client = ClobClient(
host="https://clob.polymarket.com",
key_id="YOUR_KEY",
secret="YOUR_SECRET",
)

markets = client.get_markets(active=True)
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

for market in markets[:5]:
print(market["question"], market["market_id"])


if __name__ == "__main__":
main()
10 changes: 9 additions & 1 deletion examples/get_orderbook.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
Example: Fetch a single orderbook by token_id

Requires:
- CLOB_API_URL (optional, defaults to Polymarket public endpoint)
"""

from py_clob_client.client import ClobClient
import os
from dotenv import load_dotenv
Expand All @@ -18,4 +25,5 @@ def main():
print("orderbook hash", hash)


main()
if __name__ == "__main__":
main()
11 changes: 10 additions & 1 deletion examples/get_orderbooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Example: Fetch multiple orderbooks by token_id list

Requires:
- CLOB_API_URL (optional, defaults to Polymarket public endpoint)
"""

import os
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import BookParams

Expand All @@ -20,4 +28,5 @@ def main():
print("Done!")


main()
if __name__ == "__main__":
main()
14 changes: 13 additions & 1 deletion examples/get_orders.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
Example: Fetch open orders for a given market

Requires:
- CLOB_API_URL
- PK
- CLOB_API_KEY
- CLOB_SECRET
- CLOB_PASS_PHRASE
"""

import os

from py_clob_client.client import ClobClient
Expand Down Expand Up @@ -28,4 +39,5 @@ def main():
print("Done!")


main()
if __name__ == "__main__":
main()