Developer

Polymarket API Trading: A Developer's Guide

Polymarket exposes a public API that lets you read markets and trade programmatically. This is a conceptual map of how it fits together — the two APIs, authentication, orders, and the rate limits that shape any system you build on top.

If you can write code, you don't have to click buttons. Polymarket's API lets you pull market data, authenticate a wallet, and place and cancel orders programmatically — the foundation of any custom trading system. This guide is a high-level orientation, not a line-by-line reference; APIs change, so always confirm specifics against Polymarket's current documentation.

Endpoints, parameters, and SDK method names evolve. Treat the snippets below as conceptual illustration and check the official Polymarket docs for exact, current signatures before you ship.

Key takeaways

  • Two APIs: Gamma for market discovery/metadata, CLOB for the order book and trading.
  • Trading is non-custodial — orders are signed with your wallet key; the API never holds your funds.
  • Mind rate limits and connection handling; a 24/7 trader must fail safe, not fail open.
  • Building the full stack yourself is real work — execution, risk, and monitoring are on you.

The two APIs you'll use

Polymarket's surface splits cleanly into two pieces:

A typical flow uses Gamma to find a market and its outcome token, then the CLOB to read the book and act. Most developers use Polymarket's official client libraries (available for Python and TypeScript) rather than calling the HTTP endpoints by hand, because the clients handle order signing for you.

Finding markets with Gamma

Discovery starts by querying markets and filtering down to the ones that matter — by liquidity, category, or status. Each tradable outcome has a token ID you'll carry into the CLOB calls.

# Conceptual — fetch active markets, then pick an outcome token
markets = gamma.get_markets(active=True, closed=False)
market  = markets[0]
token_id = market["tokens"][0]["token_id"]

Authentication

Trading is non-custodial: you authenticate with a wallet, and orders are cryptographically signed with your private key. The CLOB uses API credentials derived from that wallet for the trading session. In practice the client library handles the signing; your job is to supply the key securely and never expose it.

# Conceptual — initialise an authenticated CLOB client
from py_clob_client.client import ClobClient

client = ClobClient(
    host="https://clob.polymarket.com",
    key=YOUR_PRIVATE_KEY,   # load from env/secret store, never hardcode
    chain_id=137,           # Polygon
)
client.set_api_creds(client.create_or_derive_api_creds())
!

Your private key is your funds. Load it from an environment variable or secret manager, never commit it, and scope its exposure as tightly as possible. A leaked key is an irreversible loss.

Reading the order book

Before placing an order, read the book. The price you see in the UI is the top of the book; what matters for execution is the depth — how much size sits at each level. Thin books mean your order can move the price against you.

# Conceptual — inspect best bid/ask and depth
book = client.get_order_book(token_id)
best_bid = book.bids[0].price
best_ask = book.asks[0].price
spread   = best_ask - best_bid

Placing and cancelling orders

Orders specify the token, side (buy/sell), price, and size. You'll typically use limit orders for control over fill price. Always keep the order ID so you can cancel — unfilled limit orders rest on the book until they fill, expire, or you pull them.

# Conceptual — place a limit buy, then cancel by id
order = client.create_and_post_order(OrderArgs(
    token_id=token_id,
    side="BUY",
    price=0.42,
    size=25,
))
client.cancel(order_id=order["orderID"])

Market vs. limit orders

The CLOB supports the two order types you'd expect, and choosing between them is a real decision, not a detail:

For most automated strategies, limit orders priced intelligently against the book are the default, with marketable orders reserved for exits that can't wait. Always size the order against visible depth — an order larger than the resting liquidity will walk the book and fill at progressively worse prices.

Handling resolution and settlement

Unlike ordinary markets, Polymarket positions can resolve: when the underlying event is decided, the market settles and winning outcome tokens become redeemable. Your system has to account for this. A position you're holding can settle while you sleep, changing your exposure without any order on your part.

Practically, that means tracking each market's status and resolution source, not just its price, and handling the case where a market closes or resolves mid-strategy. Resolution can also be delayed or disputed, so don't assume a position frees up the instant the event happens. Build your accounting around "this market may resolve at any time" rather than treating settlement as an afterthought.

A minimal trading loop, conceptually

Tie the pieces together and the skeleton of an automated trader is straightforward. The hard parts aren't in this loop — they're in the strategy, the risk checks, and the error handling around it:

# Conceptual — the shape of a single decision cycle
while running:
    market   = gamma.refresh(token_id)        # latest metadata + status
    if market.resolved:
        handle_resolution(market); continue

    book   = client.get_order_book(token_id)
    signal = strategy.evaluate(market, book)  # your edge lives here

    if signal and risk.allows(signal):     # risk can VETO any trade
        size  = risk.size_for(signal)         # hard caps enforced here
        client.create_and_post_order(build_order(signal, size))

    sleep(interval)                           # respect rate limits

Notice the two non-negotiables: the risk layer can veto any trade the strategy proposes, and it — not the strategy — decides size. That's the same discipline described in Polymarket Risk Management 101, expressed in code.

Rate limits and reliability

Any system that trades around the clock has to respect rate limits and survive the messy reality of networks. Build in:

When to build vs. when to use an engine

The API gives you everything you need to build a trader — and "everything you need to build a trader" is a lot of software. Beyond placing orders, a production system needs strategy logic, position sizing, risk guardrails, monitoring, alerting, and 24/7 operation. If that's the project you want, the API is excellent and well-documented.

If you'd rather not build and maintain all of that, a managed engine gives you the same execution layer with the operational burden handled — see the complete guide to automating Polymarket trading for how the two paths compare.

Frequently asked questions

Does Polymarket have a public API?

Yes. Polymarket exposes a Gamma API for market data and discovery and a CLOB API for the order book and trading, with official client libraries for Python and TypeScript. Always check the current documentation for exact endpoints and signatures.

Is trading via the Polymarket API non-custodial?

Yes. Orders are signed with your own wallet key and your funds stay in your wallet and Polymarket's smart contracts — the API never takes custody. That also means securing your private key is entirely your responsibility.

What language should I use to build a Polymarket bot?

Python and TypeScript are the best-supported, since Polymarket maintains official clients for both. Choose whichever you're more fluent in; the concepts — discovery, auth, order book, orders — are identical across them.

Do I have to build everything myself to trade programmatically?

No. The API gives you the building blocks, but a production trader also needs strategy, risk controls, monitoring, and 24/7 operation. If you'd rather not build and maintain all of that, a managed engine provides the execution layer for you — see the guide to automating Polymarket trading.

Skip the plumbing

antflow is the execution, risk, and monitoring layer — built on the Polymarket API so you don't have to be. Configure your strategy instead of maintaining infrastructure. Join the waitlist.

Join the waitlist