PolySimulator Python SDK
Mirrors Polymarket's unified py-sdk —
polysim_polymarketis a paper-mode mirror ofpolymarket-client0.20.1: every method of the sync + async PublicClient/SecureClient (the ones paper trading cannot serve raiseNotSupportedOnPaper), trading, and core streams. Swap the import prefix + host + auth and your py-sdk bot runs on paper. Compat matrix ↓
The official Python client for the PolySimulator paper-trading API. One package, three import surfaces:
| Import surface | Use it when |
|---|---|
polysim_sdk |
You're starting fresh. A clean, modern client — sync and async, WebSocket streaming, pagination iterators, typed exceptions. |
polysim_clob_client |
You already have a bot written against Polymarket's py-clob-client. This is a drop-in mirror — port by changing the import path, the host, and the auth call. |
polysim_polymarket |
You target Polymarket's newer unified py-sdk (pip install polymarket-client, import polymarket). A paper-mode mirror of its unified surface — sync and async PublicClient / SecureClient (reads, account/auth, trading) plus core realtime streams. Port by swapping the import prefix + host + auth. See Polymarket py-sdk (v2) mirror — read the sim→real seam contract and compat matrix before you rely on a surface area. |
Which client should I use?
Pick by the Polymarket client your bot already uses:
| Your bot uses | Use against PolySimulator | What changes |
|---|---|---|
Polymarket's unified SDK, polymarket-client (import polymarket, the client Polymarket's docs recommend) |
polysim_polymarket from this package |
The import prefix, the host and the auth. polymarket-client cannot be pointed at another host, so it needs this mirror. Tracks polymarket-client 0.20.1; see PARITY.md. |
py-clob-client-v2 (import py_clob_client_v2) |
The real py-clob-client-v2, unchanged |
Only the host and the credentials: host="https://api.polysimulator.com/v1", ApiCreds(api_key="ps_live_...", api_secret=<any base64>, api_passphrase=<any>), any throwaway private key (signatures are not checked). Needs an API release with the v2-client fixes (/version returns 2, /clob-markets, fill ids in tradeIDs); on an older API create_order fails with unsupported order version. |
Legacy py-clob-client v1 (import py_clob_client, archived upstream) |
polysim_clob_client from this package |
The import path, the host and the auth call; see Migrating from py-clob-client. |
| Nothing yet | polysim_sdk |
Native client with paper-only extras (wallets, settlements, backtests). |
PolySimulator is paper trading, so there is no on-chain anything: no private
key, no chain_id, no funder, no signature_type, no EIP-712 signing, no USDC
allowance/approval transactions, no web3/Polygon RPC. The runtime dependencies
are httpx, websockets, pydantic and typing_extensions. Authentication is a single ps_live_* API key sent as
the X-API-Key header (get one).
Install
Targets Python 3.10+.
Upgrading from 0.6.0? Read the changelog first: 0.7.0 no longer retries a timed-out write the server cannot dedupe (it raises
OutcomeUnknownErrorinstead), and it paces requests from the server's rate-limit headers.
pip install polysimulator
The install name is
polysimulator; the import name stayspolysim_sdk(likepip install pillow→import PIL). The olderpolysim-sdkname is now a thin alias that installspolysimulatorfor you, so existing installs keep working.
From a checkout of this directory (for development):
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]" # editable install + pytest/ruff/mypy/build/twine
Provide your key via the POLYSIM_API_KEY environment variable (recommended) or
pass it to the constructor:
export POLYSIM_API_KEY="ps_live_…"
The SDK talks to production (https://api.polysimulator.com) by default; leave
POLYSIM_BASE_URL unset. Keys belong to one deployment's database, so a
production key is rejected with 401 anywhere else.
Try public market data without a key
Market data is public, so you can explore before creating a key. With no
POLYSIM_API_KEY set, the client sends no X-API-Key header:
from polysim_sdk import PolySimClient
with PolySimClient() as client: # no key needed for these
markets = client.list_markets(limit=20, active_only=True)
btc_5m = client.list_updown(asset="BTC", interval="5M", live=True)
print(client.get_spot("BTC")["price"]) # live BTC spot
print([t["tier"] for t in client.tiers()]) # the rate-limit tiers
# Order books are public by outcome-token id. token_ids is a JSON-encoded
# string, like outcomes. Read the round that is running right now: a
# round that just ended stays listed for a moment, but its book is gone.
import json
from datetime import datetime, timezone
def ts(s): return datetime.fromisoformat(s.replace("Z", "+00:00"))
now = datetime.now(timezone.utc)
current = next(r for r in btc_5m if ts(r["start_date"]) <= now < ts(r["end_date"]))
up_token = json.loads(current["markets"][0]["token_ids"])[0]
book = client.get_book_by_token(up_token) # levels in Polymarket's order: best last
best_bid = max((float(l["price"]) for l in book["bids"]), default=None)
best_ask = min((float(l["price"]) for l in book["asks"]), default=None)
print("Up:", best_bid, "/", best_ask) # one side can be empty near the close
Books and markets looked up by condition id (get_book(cid),
get_market(cid)) still need a key today. Without one, read the book by token
id as above.
Account, order and key calls (me(), balance(), place_order(), the
WebSocket streams, ...) need a key. Without one they raise
ApiKeyRequiredError (an ApiError with status_code == 401):
HTTP 401: This call needs an API key. Create one at https://polysimulator.com/console and set POLYSIM_API_KEY. [code=MISSING_AUTH]
ClobClient() and the polysim_polymarket PublicClient() construct without
a key the same way.
Get an API key
- Sign in at polysimulator.com.
- Open the developer console at polysimulator.com/console and
create a key. The raw
ps_live_…value is shown once; copy it then. export POLYSIM_API_KEY="ps_live_…".
No browser (headless / CI)? Mint your first key with the access token of a programmatic Supabase sign-in, then use the key it returns for everything else:
from polysim_sdk import PolySimClient
created = PolySimClient.bootstrap(jwt="<supabase access token>", name="my bot")
print(created["raw_key"]) # shown once
bootstrap only works while the account has no keys; after that, call
create_key(name=...) from a client that already holds one. Leave tier unset
in both and the key is minted at the tier your plan entitles you to.
Quickstart — native polysim_sdk
from polysim_sdk import PolySimClient
with PolySimClient() as client: # POLYSIM_API_KEY from env
me = client.me()
print(me["balance"]) # your trading balance (a JSON string)
market = client.list_markets(limit=20, hot_only=True, active_only=True)[0]
cid = market["condition_id"]
book = client.get_book(cid) # by condition id (+ outcome=/depth=)
asks = book.get("asks") or [] # levels: [{"price","size"}, ...]
best_ask = min((float(a["price"]) for a in asks), default=None)
print("best ask:", best_ask) # lowest ask = best price to buy at
# …or by outcome-token id, the Polymarket-native way:
# token_book = client.get_book_by_token("<outcome-token-id>")
fill = client.place_order(
market_id=cid,
side="BUY",
outcome="Yes", # match the market's own `outcomes` label
quantity=10,
order_type="market",
price="0.99", # worst-acceptable fill (Yes < $1 → "any fill")
)
print(f"filled {fill['status']} @ {fill.get('price')}")
Async is the same API with await:
import asyncio
from polysim_sdk import AsyncPolySimClient
async def main():
async with AsyncPolySimClient() as client:
me = await client.me()
print(me["balance"])
asyncio.run(main())
me() also reports the tier and permissions of the key you authenticated
with (e.g. ["read", "trade"]), and tiers() returns the live rate-limit
ladder. entitlements() does not work with an API key: the endpoint behind it
accepts only a signed-in web session, so the method raises PolySimError saying
so rather than returning a 401.
Finding BTC Up/Down markets
Short-horizon crypto Up/Down markets — "is BTC/ETH/SOL/… up or down over
this window" resolving on a 5-minute … daily horizon — are the platform's
most-traded product. They have a dedicated endpoint and do not show up
through list_markets(q="btc") (free-text search is the q filter). Use
list_updown / get_updown:
with PolySimClient() as client:
# Currently-tradeable BTC 5-minute windows, filtered server-side:
live = client.list_updown(asset="BTC", interval="5M", live=True)
window = live[0]
print(window["slug"]) # btc-updown-5m-1781400900
print(window["time_range"]) # "9:35PM-9:40PM ET"
print(window["group_item_threshold"]) # resolution strike (None until the window opens)
# Outcome tokens live in the nested markets[] array (JSON-string fields):
nested = window["markets"][0]
print(nested["outcomes"]) # '["Up", "Down"]'
print(nested["outcome_prices"]) # '["0.595", "0.405"]'
cid = window["condition_id"]
interval is one of 5M / 15M / 1H / 4H / daily (uppercase).
live=True keeps only active and not closed and not resolved windows.
The live underlying spot price plus the available assets/intervals come from
the full payload via get_updown:
payload = client.get_updown(asset="BTC")
btc = (payload.get("crypto_prices") or {}).get("BTC") or {}
print(btc.get("price")) # 64588.0 — live BTC/USD (coingecko)
print(payload["available_intervals"]) # ['5M', '15M', '1H', '4H', 'daily']
print(payload["interval_counts"]) # {'5M': 169, '15M': 402, ...}
The spot price can be momentarily absent right at a window boundary (the payload is cached and the feed can lag a second or two), so read it defensively with
.get(...)rather than chained[...]indexing.
Pricing an Up/Down market
The raw order book (get_book) on an Up/Down market is a synthetic
placeholder — its asks[0] sits near ~0.99 and is not a real resting quote.
For price, use the market's own fields instead:
window["live_price"]→{"buy": 0.595, "sell": 0.405, ...}(current marketable prices)nested["outcome_prices"]→ the latest Up/Down implied probabilities- the realised
pricereturned byplace_order— the SDK fills against the real internal book and reports the true fill price,fee, andbook_walk_levels
A market order with a worst-price cap still fills correctly regardless; just
don't read get_book(...)["asks"][0] as a tradeable quote on these markets.
Drop-in
polysim_clob_clientusers:get_midpoint,get_price,get_spreadandcalculate_market_priceread the outcome token's synthetic ~0.99 ladder on Up/Down markets — they are not the underlying asset price. For the asset, use the native reads below.
Up/Down for HFT: strike, spot, and a push feed
The two numbers an Up/Down strategy actually trades on — the strike ("price to beat") and the live underlying spot — have dedicated reads on the native client, plus a push stream and a few pure helpers:
from polysim_sdk import PolySimClient
from polysim_sdk import updown
with PolySimClient() as client:
live = client.list_updown(asset="BTC", interval="5M", live=True)
window = updown.next_to_expire(live) or live[0] # the contract closing soonest
cid = window["condition_id"]
strike = client.get_price_to_beat(cid)["price"] # GET /prices/ptb/{cid}; 404 = not set yet
spot = client.get_spot("BTC")["price"] # GET /prices/live/BTC — live underlying
# all spots in one call: client.get_spots()["prices"]
print(updown.ptb_distance(spot, strike)) # signed price units; >0 ⇒ "Up" in the money
print(updown.ptb_distance_bps(spot, strike)) # same, in bps of the strike
print(updown.seconds_to_expiry(window)) # time left on the window
get_price_to_beat raises ApiError with status_code == 404 while a window's
strike is still pending — that is "not set yet", not "market absent". It accepts
a condition_id or an outcome-token id. Its source field tells you the
provenance: polymarket_open_price / polymarket_scrape / gamma_event_metadata
(Polymarket's own reported strike) and chainlink_onchain / chainlink_timeline
(the resolution oracle) are the settlement strike; gamma_api / cryptocompare
are best-effort fallbacks — treat them as indicative.
The polysim_sdk.updown helpers are pure functions over the row dicts (no
network, tolerant of missing fields): seconds_to_expiry, is_window_open,
price_to_beat (reads the strike off a row you already have), ptb_distance /
ptb_distance_bps, open_windows, next_to_expire, plus the ASSETS /
INTERVALS vocab tuples. For a streaming tap on the underlying, see
SSE: live underlying spot below.
New-market warm-up: retry order placement on a 404
A brand-new market — especially the 5m Up/Down windows that roll every few
minutes — has a short window after creation before it enters the
order-validation catalog. An order placed in that window transiently fails with
a 404 (code="MARKET_NOT_FOUND"). The window is short — on the order of ~30s,
the Up/Down roll cadence — but it is a cadence, not a guarantee.
The SDK does not auto-retry 404s (by design — a 404 is normally permanent), so a bot trading freshly-rolled markets should catch and retry that one signal with backoff. The native client ships a small opt-in helper that retries only the warm-up 404 and re-raises everything else (and the 404 itself once the budget is spent):
from polysim_sdk import PolySimClient, retry_on_market_warmup
with PolySimClient() as client:
fill = retry_on_market_warmup(
lambda: client.place_order(
market_id=cid, side="BUY", outcome="Up", amount="10", price="0.99",
),
attempts=6, base_delay=2.0, # ~2,4,8,16,30s capped backoff between tries
)
It wraps any zero-argument callable, so the same helper works with a
polysim_clob_client drop-in call (e.g.
retry_on_market_warmup(lambda: clob.create_and_post_order(args))); the drop-in
surfaces the same condition as a PolyApiException with status_code == 404.
See Errors for the standalone retry-on-404 pattern if you'd rather
roll your own.
Polymarket compatibility
polysim_clob_client is a drop-in mirror of Polymarket's
py-clob-client v1 — the
0.x line, surface-parity with v1 0.34.x. Method names, argument shapes, and
return shapes match v1, so a v1 bot ports by changing three things (import path,
host, auth) and deleting the on-chain prelude — see
Migrating from py-clob-client below.
Polymarket's py-clob-client-v2
is a separate PyPI package (pip install py-clob-client-v2, import
py_clob_client_v2). PolySimulator serves its CLOB routes under /v1, so the
real v2 client runs against the paper API with a host and credentials change
(see Which client should I use?); there is no
polysim_* wrapper for it. That needs an API release with the v2-client fixes
(/version returns 2; on an older API create_order fails with
unsupported order version).
| Polymarket client | Compatibility |
|---|---|
py-clob-client v1 (< 2.0; latest 0.34.6) |
✅ Drop-in via polysim_clob_client |
py-clob-client-v2 (1.2.x) |
✅ The real client, host="https://api.polysimulator.com/v1" (needs the API release with the v2-client fixes) |
unified py-sdk (polymarket-client, import polymarket; 0.20.1) |
🔶 Paper-mode mirror via polysim_polymarket — every method of the sync + async PublicClient / SecureClient (reads, account/auth, trading) + core streams; split/merge can update paper wallets, other on-chain methods are paper no-ops, and the Gamma/Data reads PolySimulator cannot serve raise NotSupportedOnPaper. See below and the compat matrix |
The v2-only concepts — EIP-712 v2 signing, pUSD collateral, protocol-side fees, builder codes — have no analog in paper trading, so there is nothing to port: you drop them entirely.
Polymarket py-sdk (v2) mirror
Polymarket also ships a newer unified Python SDK, published to PyPI as
polymarket-client and imported
as polymarket. It folds the CLOB, gamma (markets/events), data, RFQ, and
realtime-stream surfaces into one client and returns typed pydantic models
(OrderBook, Market, LastTradePrice, …) instead of raw dicts.
polysim_polymarket is our paper-mode mirror of that SDK — the package we
call the v2 mirror in this repo (the polysim_clob_client mirror above is
v1).
It mirrors the unified client family in paper mode: sync and async
PublicClient and SecureClient, the authenticated trading write surface,
the account/auth/order reads, paper split/merge and the remaining
on-chain methods (as paper no-ops), the
rewards/builder/RFQ stubs, and the core realtime streams (market /
user / crypto_prices). Every other polymarket-client method — the
Gamma/Data reads (events, series, tags, comments, sports, portfolio/positions,
leaderboards), perps, session keys and the like — exists with py-sdk's signature
and raises NotSupportedOnPaper. The exact
support level for every surface area is in the compat matrix
below; the precise places paper diverges from real are in the
sim→real seam contract.
Read both before you rely on a surface area — this is a paper-trading mirror,
not a drop-in for everything py-sdk does.
The port is the same mechanical swap as v1 — change the import prefix, the host, and the auth:
- from polymarket import SecureClient
+ from polysim_polymarket import SecureClient
- client = SecureClient.create(private_key="0x…") # real Polymarket wallet + EIP-712 signing
+ client = SecureClient(host="https://api.polysimulator.com", api_key="ps_live_…")
# unchanged from here on — same method names, same keyword-only call shapes,
# same model field names/types. A read:
# ``asset_id`` is py-sdk 0.8.0's canonical spelling; ``token_id`` still works.
book = client.get_order_book(asset_id="711811…")
# py-sdk OrderBook ordering: bids ascending (best = bids[-1]), asks
# descending (best = asks[-1]).
print(book.bids[-1].price, book.asks[-1].price, book.asset_id)
# …and a trade — flat keyword args, py-sdk's SignedOrder / OrderResponse:
signed = client.create_market_order(asset_id="711811…", side="BUY", amount=10)
resp = client.post_order(signed) # paper-accepted, not on-chain-settled
print(resp.order_id, resp.status)
(The PublicClient swap is identical — drop the auth entirely:
PublicClient(host="https://api.polysimulator.com", api_key="ps_live_…") against
polymarket's PublicClient().)
The model field names and types (OrderBook, OrderBookLevel,
LastTradePrice, PriceHistoryPoint, Market — with its nested .state
MarketState — Page, Paginator, the trading types OrderSide / OrderType
/ SignedOrder / OrderResponse / CancelOrdersResponse, and the RFQ types) all
track py-sdk so the swap stays mechanical, and every public name a bot imports is
re-exported off the package root, exactly as on real Polymarket — including the
named errors the surface raises (UserInputError,
InsufficientLiquidityError, UnexpectedResponseError), so
from polymarket import UserInputError survives the prefix swap unchanged. (Like
py-sdk, MarketState itself is not promoted to the package root — it's reached
via market.state or polysim_polymarket.models.MarketState, never from polysim_polymarket import MarketState.) The one deliberate divergence is the
error-tree base name: those three named errors subclass the
py-clob-client-lineage PolyException / PolyApiException base (shared by
identity with the v1 mirror) rather than py-sdk's PolymarketError, so a bot
that catches the broad base by name needs except PolyException here vs except PolymarketError on real Polymarket; an except UserInputError block is
identical on both:
from polysim_polymarket import PublicClient, OrderBook, Environment, PolyException, Paginator
The sim→real seam contract: what paper mode does and doesn't do
This is a paper-trading mirror. The call shapes and model fields match py-sdk so the port is mechanical, but paper mode is not Polymarket — it has no chain, no wallet, and its own market universe. Every place paper deliberately diverges from real Polymarket is enumerated here, up front, so a bot author knows exactly what they're getting before they rely on a surface area:
-
Signing is inert (accepted, never settled on-chain). The authenticated trading write surface IS implemented —
create_limit_order/create_market_order/place_limit_order/place_market_order/post_order/post_orders/cancel_order/cancel_orders/cancel_all/cancel_market_orders, with py-sdk's flat keyword args andSignedOrder/OrderResponse/CancelOrdersResponsereturn models. But paper trading needs no signer, so signing is accepted-and-inert: the order is produced with an empty signature and the unsigned paper body is submitted. There is no EIP-712 signing, no on-chain settlement, and no Polygon transaction — the fill happens entirely in PolySimulator's paper matching engine. -
Collateral / balances are PAPER. Your balance is PolySimulator's paper balance (the
balancefromme()on the native client), not an on-chain USDC balance.get_balance_allowance(asset_type="COLLATERAL")reports the paper account's cash collateral;get_balance_allowance(asset_type="CONDITIONAL", asset_id=…)reports the conditional-token balance — the open position's share count for that token, in base units (matching real py-sdk, where a CONDITIONAL read returns the held conditional token, not collateral; a flat position is0). There is no real USDC, no allowance/approval transaction, no funder wallet — soallowancesis always empty. -
A settled trade carries the per-fill fee RATE, not a fee amount. PolySimulator's matching engine charges and records a real (paper) fee on each fill. What it surfaces over the typed read surface is the fee rate: a settled trade read via
list_account_tradesreturns aClobTrademodel carrying the per-fill fee rate asfee_rate_bps(basis points — the category taker rate applied to the fill,0for fee-free fills), exactly matching py-sdk'sClobTrade. What IS surfaced: the per-fillfee_rate_bps. What is NOT surfaced: a realized per-fill fee amount — there is nofee/fee_usdcfield onClobTrade(the only model carrying those isBuilderTrade, whose reads are stubbed — see below), so the sim's debited fee amount is not exposed as a typed field on the implemented read surface. What is NOT mirrored at all: Polymarket builder fees (the builder-attribution program — see the builder stub row), and any protocol-side / pUSD v2 fee economics; thebuilder_code=kwarg on the order builders is accepted for parity but stays inert (no builder fee taken, no builder-revenue ledger). On maker/taker: the sim classifies a marketable-at-placement GTC (one that crosses the book on submit) as a taker and charges the taker fee, matching Polymarket; only a genuinely-resting GTC that is filled later — when the market moves into it — is booked as a $0-fee maker. This is a fidelity match, not a gap. -
The market universe is PolySimulator's, NOT Polymarket's live universe. Reads resolve against the markets PolySimulator carries, which is a curated subset of Polymarket plus the platform's own crypto Up/Down products. A
token_id/condition_id/ slug that exists on Polymarket but not in PolySimulator's universe will not resolve here. Do not assumelist_markets/get_marketreturns the same set, count, or ordering as real Polymarket. -
Split/merge use the paper API when the server offers it (since 0.7.0). Sync and async
split_position(condition_id=..., amount=...)andmerge_positions(condition_id=..., amount=...)callPOST /v1/splitandPOST /v1/mergewhen the server supports them. The hosted API does not offer these endpoints yet, so today both calls are accepted as no-ops that move no cash or shares, and the client logs one warning saying so. Once the endpoints are enabled, the same calls change the paper wallet: split debits API-wallet cash and adds a full set of YES/NO shares; merge removes the shares and credits cash. Amounts use six-decimal base units (1_000_000= $1); cash moves to cents, rounding a split debit up and a merge credit down. A successful handle'stransaction_idis the server operation ID;wait()returns immediately.amount=0stays a local no-op, andamount="max"merges the smaller holding. Missing endpoints (404 HTTP_404, or a bare 404) fall back to a no-op with one warning per client; domain errors such as insufficient funds,MARKET_NOT_FOUNDorWALLET_NOT_FOUNDpropagate.legs=combo operations raiseNotImplementedErrorafter the existing input guards. -
Other on-chain methods are instant PAPER no-ops.
approve_erc20/approve_erc1155_for_all/transfer_erc20/redeem_positions/setup_trading_approvals/setup_gasless_walletaccept their paper input guards, move no cash or positions, and return placeholder transaction handles. Address checks validate the 40-hex format, not an EIP-55 checksum. -
Rewards / builder / RFQ are honest stubs. The rewards/scoring reads return honest empties (
get_order_scoring→False, thelist_*rewards reads → empty paginators,get_reward_percentages→{}, …) — the paper rewards engine is a separate roadmap item, so a reward-accounting loop runs and truthfully finds nothing. The builder-attribution reads (get_builder_volumes/list_builder_trades/get_builder_fee_rates/list_builder_leaderboard) keep py-sdk 0.10's signatures but raiseNotSupportedOnPaper— there is no builder economy on paper. The RFQ types re-export for type-hint parity, and every RFQ action (fetch_rfq_status, the asyncopen_rfq_session, the combo quote calls) raisesNotSupportedOnPaper— RFQ quoting is not simulated. -
Streams are core-topics-only, with documented seams.
subscribe()is async-only (sync clients have nosubscribe, matching py-sdk) and covers py-sdk's CORE topics:market(MarketSpec),crypto_prices(CryptoPricesSpec), and the authenticateduserfeed (UserSpec, secure client only). The sports / comments / equity topics are deferred (their specs/events aren't shipped). The documented stream seams: the market feed is top-of-book, not L2 (it emitsprice_change/last_trade_price, never abookevent — callget_order_bookfor the ladder);MarketSpec.token_idsare the SDK'scondition_id:LABELtokens (not raw Polymarket numeric token ids); stream id fields are plainstr(not py-sdk's hex-validated newtypes); and the lifecycle market events (NewMarketEvent,MarketResolvedEvent, …) are defined formatch-parity but never emitted on paper. Full detail in Realtime streams. -
Read-model fidelity gaps. A handful of implemented reads are present but narrower than py-sdk's (e.g.
Marketis a focused identity+state subset, not the full gamma model;list_marketsaccepts py-sdk's full gamma keyword set but only forwards the few PolySimulator honours;get_last_trade_pricereports a constantside="BUY"from a book snapshot with no trade side;Decimalstring-form may carry extra trailing zeros;0is the no-quote sentinel). None break the call shape — see Fidelity gaps.
Because the real py-sdk is a superset, swapping back to real Polymarket only ever adds capability over this seam — it never breaks a bot that stuck to the mirrored surface and respected the seams above.
Compat matrix
Pinned to
polymarket-client==0.20.1—tests/test_polymarket_full_surface_parity.pychecks every public method of the four clients against the installed pin, andPARITY.mdis the generated per-method table (scripts/gen_polymarket_parity.py).
Support level for every py-sdk surface area, cross-checked against what's
actually implemented in polysim_polymarket:
| Surface area | Support | Notes |
|---|---|---|
CLOB asset ids (token_id → asset_id, v0.8.0) |
✅ Full parity | py-sdk 0.8.0 renamed the CLOB "token" concept to "asset" so one id can name either a CTF outcome-token id or a protocol-v2 position id. The mirror tracks it exactly: every client method takes asset_id= / asset_ids= with the legacy token_id= / token_ids= retained as a mutually-exclusive alias; every renamed read model exposes asset_id and a deprecated token_id computed field (so it survives model_dump()); PriceRequest is upstream's tuple-compatible dataclass; MarketSpec takes asset_ids= with token_ids= deprecated; LastTradePriceForAsset aliases LastTradePriceForToken. Resolver error strings match upstream verbatim. Nothing was removed — no existing call breaks. Paper caveat: accepting a v2 position id is a naming widening only; paper mode has no v2 combo positions, so such an id simply does not resolve against PolySimulator's market universe (the same "unknown id" seam as any Polymarket token id we do not carry). |
| Protocol-v2 routing (v0.8.0/0.9.0) | 🟡 Paper seam (inert) | 0.9.0 routes v2 position ids to a different exchange address / position manager and threads a protocol_version through EIP-712 order signing (UnsignedOrder.protocol_version, defaulted "2"). All of that is on-chain routing, which is a paper no-op here — the mirror signs nothing and settles in the paper matching engine. Nothing for a paper bot to configure; the swap to real Polymarket picks it up automatically. |
| Public reads (CLOB market data) | ✅ Full parity | get_order_book(s) / get_midpoint(s) / get_price(s) / get_spread(s) / get_last_trade_price(s) / list_price_history (0.10+; get_price_history is a deprecated alias until 0.9.0) / estimate_market_price / get_market / list_markets — sync + async, identical call shapes & model fields (subset/sentinel gaps documented; see Fidelity gaps for the Market subset + the ignored list_markets filters). |
| Secure reads (CLOB market data) | ✅ Full parity | The secure client shares the public reads, identical signatures. |
| Account / auth | 🟡 Paper seam | fetch_api_keys / delete_api_key / get_balance_allowance / is_gasless_ready / get_closed_only_mode / get_notifications / get_order / list_open_orders / list_account_trades implemented over paper auth (single ps_live_* key). Note: is_gasless_ready / get_closed_only_mode / get_notifications are constant honest stubs (return True / False / () with no network call), distinct from get_balance_allowance / get_order / list_open_orders / list_account_trades, which are genuinely backed by the paper API. py-sdk's wallet-auth end_authentication and the drop_notifications write raise NotSupportedOnPaper. Since 0.20, list_open_orders(asset_id=...) needs market= (py-sdk's rule). |
| Trading (orders) | 🟡 Paper seam | Full write surface (create_* / place_* / post_order(s) / cancel_*) with py-sdk's flat kwargs + SignedOrder / OrderResponse / CancelOrdersResponse. Signing inert, settled in paper engine, not on-chain. send_order_heartbeat (0.14) uses POST /v1/heartbeats and needs an API with Polymarket's heartbeat_id contract (an API on the legacy interval_ms heartbeat raises NotSupportedOnPaper); the wallet-wide list_wallet_open_orders / cancel_wallet_orders / cancel_all_wallet_orders (0.18, Deposit Wallet only) raise NotSupportedOnPaper. |
| On-chain (ERC-20/1155, split/merge/redeem, approvals) | 🟡 Paper seam | Since 0.7.0, market split/merge call the paper API when the server offers it and then change cash/positions, with server errors propagated. The hosted API does not offer it yet, so today they are no-ops with one logged warning; zero amounts are always no-ops. Combo positions raise NotImplementedError. Other methods remain instant no-ops with placeholder handles. |
| Rewards / scoring | ⚪ Stub (honest empties) | get_order(s)_scoring / list_* rewards / get_total_earnings_* / get_reward_percentages implemented but return honest empties — no paper rewards engine yet. |
| Builder attribution | ❌ Not supported | get_builder_volumes(interval=, bucket_limit=) / list_builder_trades / get_builder_fee_rates / list_builder_leaderboard(window=, page_size=) keep the 0.10+ signatures and raise NotSupportedOnPaper; builder API key CRUD likewise. No builder economy on paper. |
| RFQ | ⚪ Stub (types + NotImplementedError) | RFQ types re-export for type-hint parity, including the v0.6.0 Combo RFQ additions (ComboQuote, RfqStatus, RfqErrorDetail, …). py-sdk's sync SecureClient has exactly one RFQ-named method, fetch_rfq_status (v0.6.0); the mirror invents none. The async open_rfq_session and every Combo RFQ action (request_combo_quote / accept_combo_quote / fetch_rfq_status / wait_for_combo_fill) raise NotSupportedOnPaper (a NotImplementedError) — no live maker/matching session simulated. |
| Market stream | 🟡 Paper seam | subscribe(MarketSpec) → price_change / last_trade_price over /v1/ws/prices. TOB, not L2 (no book event); condition_id:LABEL token keying; lifecycle events defined-but-never-emitted. |
| User stream | 🟡 Paper seam | subscribe(UserSpec) (secure only) → order/trade fills over the authenticated executions channel; UserSpec.markets is a client-side filter; lean frames with honest derivations. |
| Crypto stream | 🟡 Paper seam | subscribe(CryptoPricesSpec) → Binance / Chainlink ticks, routed by exact source label, over the spot SSE feed. |
| Sports / comments / equity / Chainlink-TWAP / Perps streams | 🔴 Deferred | SportsSpec / CommentsSpec / EquityPricesSpec (+ the RtdsSpec base alias), CryptoPricesChainlinkTwapSpec (v0.7.1 — a 30s/60s-averaging-window variant of the already-implemented CryptoPricesSpec; no paper Chainlink TWAP source to stream from), the whole Perps stream-spec family (PerpsSpec + 6 topic specs, v0.2.0) and the 0.11+ PolyBolt specs (CryptoPriceSpec / CryptoTwapPriceSpec / EquityPriceSpec / EquityTwapPriceSpec) are not shipped; pass a single CORE spec per subscribe(). |
| Not supported on paper (Gamma events/series/tags/comments/sports, Data API wallet reads and analytics, perps, session keys, Deposit Wallet orders, collateral return, relayer transactions, combo markets) | ❌ NotSupportedOnPaper | Present with py-sdk's exact names and parameters (so imports and calls bind), and raise polysim_polymarket.NotSupportedOnPaper naming the method. The full list is below. Since 0.8.0 this replaces the old "absent, AttributeError" deferral. |
Legend — ✅ Full parity: same behaviour & shape as py-sdk (documented
narrowness aside). 🟡 Paper seam: implemented with paper-mode semantics
(see the seam contract). ⚪ Stub: importable & callable, returns an honest
empty or raises NotSupportedOnPaper — no fabricated data. ❌ Not supported:
present with py-sdk's signature, raises NotSupportedOnPaper.
Methods that raise NotSupportedOnPaper
polysim_polymarket.NotSupportedOnPaper subclasses both the shared
PolyException base and NotImplementedError; its method attribute names the
call. Generated from polymarket-client by scripts/gen_polymarket_parity.py:
- Gamma events, series, tags, comments, clarifications, sports, profiles (Polymarket's Gamma events, series, tags, comments, clarifications, sports and profiles are not mirrored; markets are (get_market / list_markets)):
get_comment_thread,get_event,get_event_tags,get_market_tags,get_public_profile,get_related_tag_resources,get_related_tags,get_series,get_sports,get_sports_market_types,get_tag,list_comments,list_comments_by_user_address,list_events,list_market_clarifications,list_series,list_tags,list_teams,search - Data API reads by wallet address (Polymarket's public Data API reads keyed by a Polygon wallet have no paper equivalent; for your own paper account use list_account_trades, list_open_orders and get_balance_allowance):
get_portfolio_value,get_trader_leaderboard_standing,get_user_pnl,get_user_stats,get_user_volume,list_activity,list_positions,list_trader_leaderboard,list_trades - Venue-wide Data API analytics (venue-wide Data API analytics (holders, open interest, live volume, resolutions, token references, winners) are not mirrored):
get_event_live_volume,get_open_interests,get_resolutions,get_token_references,list_biggest_winners,list_market_holders - Rebates and reward-market catalogue (maker rebates and the reward-market catalogue are not simulated):
get_current_rebates,list_reward_markets - Builder attribution and builder API keys (builder attribution is not simulated):
create_builder_api_key,fetch_builder_api_keys,get_builder_volumes,list_builder_leaderboard,list_builder_trades,revoke_builder_api_key - RFQ and combo markets (RFQ quoting and combo markets are not simulated):
accept_combo_quote,fetch_rfq_status,list_combo_activity,list_combo_markets,list_combo_positions,open_rfq_session,request_combo_quote,wait_for_combo_fill - Deposit Wallet wide orders (Deposit Wallet session signers are not simulated; use list_open_orders, cancel_orders and cancel_all for the paper account):
cancel_all_wallet_orders,cancel_wallet_orders,list_wallet_open_orders - Session keys (session keys need an on-chain wallet; paper auth is one ps_live_ API key):
authorize_session_key,fetch_session_keys,revoke_session_key - Relayer, collateral return, on-chain settlement (relayer transactions, collateral returns and on-chain settlement are not simulated (fills settle on the paper ledger)):
end_authentication,execute_collateral_return_plan,execute_transaction,plan_collateral_return,wait_for_order_fill_settlement - Notifications write (PolySimulator has no notification feed to clear):
drop_notifications - Perps (Polymarket Perps (perpetual futures) are not simulated):
deposit_to_perps,fetch_perps_book,fetch_perps_builder_status,fetch_perps_fees,fetch_perps_instruments,fetch_perps_position_snapshots,fetch_perps_registration,fetch_perps_ticker,fetch_perps_tickers,list_perps_candles,list_perps_funding_history,list_perps_trades,open_perps_session,revoke_perps_credentials,withdraw_from_perps - Hand-written (same error):
get_builder_fee_rates,get_builder_volumes,list_builder_leaderboard,list_builder_trades;split_position/merge_positionswithlegs=;list_price_historywithas_of=;list_marketswithonchain_event_ids/request_ids/resolution_status/version.
Implemented surface — method reference
The CLOB market-data READ core (the foundation, shared by every client and backed by the same proven read path as the v1 mirror):
| Method | Returns |
|---|---|
get_order_book(*, token_id) / get_order_books(*, token_ids) |
OrderBook / tuple[OrderBook, …] |
get_midpoint(*, token_id) / get_midpoints(*, token_ids) |
Decimal / dict[str, Decimal] |
get_price(*, token_id, side) / get_prices(*, requests) |
Decimal / dict[str, dict[side, Decimal]] |
get_spread(*, token_id) / get_spreads(*, token_ids) |
Decimal / dict[str, Decimal] |
get_last_trade_price(*, token_id) / get_last_trade_prices(*, token_ids) |
LastTradePrice / tuple[LastTradePriceForToken, …] |
list_price_history(*, asset_id, interval=… | start=…, end=…, bucket_seconds=…, page_size=…) |
Paginator[PriceHistoryPoint] (timestamp / price / resolution_seconds); get_price_history is a deprecated alias returning a bare tuple until 0.9.0 |
estimate_market_price(*, token_id, side, …) |
Decimal (marginal/limit price — the worst book level touched to fill, like py-sdk; FOK underfill raises InsufficientLiquidityError, FAK falls back to the deepest level) |
get_market(*, id=…/slug=…) |
Market (with a nested .state) |
list_markets(*, …) |
Paginator[Market] — drive with .first_page() / .iter_items() |
The authenticated SecureClient adds, on top of those reads (see the
compat matrix for support level and the
seam contract
for paper semantics):
| Group | Methods |
|---|---|
| Account / auth | fetch_api_keys / delete_api_key / get_balance_allowance / is_gasless_ready / get_closed_only_mode / get_notifications / get_order / list_open_orders / list_account_trades |
| Trading | create_limit_order / create_market_order / place_limit_order / place_market_order / post_order / post_orders / cancel_order / cancel_orders / cancel_all / cancel_market_orders |
| Paper split/merge (since 0.7.0) | split_position / merge_positions — server-backed for market positions where the server offers it (the hosted API does not yet); see the seam contract above |
| Other on-chain (paper no-ops) | approve_erc20 / approve_erc1155_for_all / transfer_erc20 / redeem_positions / setup_trading_approvals / setup_gasless_wallet |
| Rewards / scoring (honest stubs) | get_order_scoring / get_orders_scoring / list_current_rewards / list_market_rewards / list_user_earnings_for_day / get_total_earnings_for_user_for_day / list_user_earnings_and_markets_config / get_reward_percentages |
| Order heartbeat | send_order_heartbeat (POST /v1/heartbeats, dead-man's switch). Needs an API with Polymarket's heartbeat_id contract. An API still on the legacy interval_ms heartbeat rejects the send and registers nothing: the mirror raises NotSupportedOnPaper and your open orders are not protected. Check that the first send succeeds before relying on it. |
| Builder (NotSupportedOnPaper) | get_builder_volumes / list_builder_trades / get_builder_fee_rates / list_builder_leaderboard |
| Everything else py-sdk has | Present with py-sdk's signature; raises NotSupportedOnPaper (see the list) |
Develop and paper-test a bot here against PolySimulator (no wallet, no key, no
gas), then run the same code on real Polymarket by swapping the prefix back to
polymarket, pointing at the real host, and supplying real credentials.
Async twins. Both clients have async counterparts — AsyncPublicClient (the
async twin of PublicClient) and AsyncSecureClient (the async twin of
SecureClient) — exposing the identical surface with every per-request method an
async def coroutine (the list_* reads stay synchronous, returning an
AsyncPaginator you then await). Construct with AsyncSecureClient(api_key=…)
or await AsyncSecureClient.create(private_key=…), drive with await, and use
async with AsyncSecureClient(…) as client: for lifecycle — exactly as py-sdk's
async client does. The async twins share the same transport-free logic as the sync
clients (no second copy), so their behaviour is identical by construction.
Seam details — implementation reference
The seam contract
above is the high-level "what diverges"; this section is the precise
implementation reference for each seam — the exact input guards, return values,
and edge behaviours. (Since 0.8.0 no py-sdk method is absent: the ones
PolySimulator cannot serve exist and raise NotSupportedOnPaper at call time,
naming the method, instead of AttributeError. The stubs below return honest
empties or raise the same error.)
- EIP-712 signing & on-chain machinery — the real-Polymarket signer /
builder-auth path. Paper trading needs no signer, so signing is
accepted-and-inert: the authenticated
SecureClient's trading write surface IS implemented (create_limit_order/create_market_order/place_limit_order/place_market_order/post_order/post_orders/cancel_order/cancel_orders/cancel_all/cancel_market_orders, with py-sdk's flat keyword args andSignedOrder/OrderResponse/CancelOrdersResponsereturn models) — it just produces an inert-signed order (empty signature) and submits the unsigned paper body. - Market split/merge are paper API operations where the server offers them.
split_positionandmerge_positionswithcondition_id=can change the API wallet's cash and positions. Successful transaction handles carry the server operation ID. Zero amounts stay local no-ops; missing endpoints (the hosted API today) keep the no-op with one warning; server domain errors propagate.legs=combo operations raiseNotImplementedErrorafter the input guards. See the seam contract for amount conversion, rounding and fallback details. 0.6.0 and earlier treat both calls as no-ops. - Other on-chain methods remain PAPER no-ops.
approve_erc20/approve_erc1155_for_all/transfer_erc20/redeem_positions/setup_trading_approvals/setup_gasless_walletvalidate paper inputs and never write to a chain or change paper balances. Their paper transaction handles return immediately with a placeholder hash andtransaction_id=None.redeem_positionsdoes not balance-check a position. Address checks are a 40-hex FORMAT check, NOT an EIP-55 checksum. The accepted shape matches py-sdk'sto_checksum_addressacceptance set — a 40-hex address with an optional0x/0Xprefix, case-insensitive — so the guard accepts every input py-sdk accepts and rejects the same malformed ones (wrong length, non-hex). Paper trading never touches a chain, so to keep the dependency surface thin the mirror does not pull ineth-utils/web3/eth_account; that means — unlike py-sdk'sto_checksum_address, which normalizes any accepted address to its EIP-55-checksummed form for on-chain use — the mirror does NOT compute the checksum normalization and returns the address unchanged (moot on paper, where the address is never used on a chain). - Rewards / scoring reads are honest empty stubs.
get_order_scoring→False,get_orders_scoring→ all-Falsedict, thelist_*rewards reads → empty paginators,get_total_earnings_for_user_for_day→(),get_reward_percentages→{}. The paper rewards engine is a separate backend roadmap item, so these return honest empties with no fabricated data — a bot's reward-accounting loop runs and truthfully finds nothing (rewards aren't earned on paper). - Builder attribution raises
NotSupportedOnPaper.get_builder_volumes/list_builder_trades/get_builder_fee_rates/list_builder_leaderboardmirror py-sdk's signatures but raiseNotSupportedOnPaper("Builder attribution is not simulated in PolySimulator paper mode.") — there is no builder fee, no builder revenue ledger, no builder leaderboard on paper. Thebuilder_code=kwarg on the order builders stays inert (no builder fee). - Collateral / balances / positions — the account balance/order reads ARE
implemented (
get_balance_allowance/get_order/list_open_orders/list_account_trades); the public Data API portfolio/positions reads, keyed by a Polygon wallet, raiseNotSupportedOnPaper(see the compat matrix). - Realtime streams (CORE topics ARE implemented). The async clients'
subscribe()covers py-sdk's CORE stream topics —market(MarketSpec→ book / price_change / last_trade),crypto_prices(CryptoPricesSpec→ Binance / Chainlink ticks), and the authenticateduserfeed (UserSpec→ order / trade fills, secure client only) — backed by ourpolysim_sdkWS + SSE transport. See the Realtime streams (v2 mirror) section below for the topic→transport map, the deferred topics, and the seams. Streaming is async-only (the syncPublicClient/SecureClienthave nosubscribe, mirroring py-sdk). The sports / comments / equity topics are DEFERRED (their specs/events aren't shipped). - RFQ — the RFQ session flow is not simulated. The RFQ types
(
RfqQuoteRequestEvent,RfqSession, the enums, the rejection errors, …) DO re-export from the package root so a maker bot's type hints survive the prefix swap, and every RFQ action (fetch_rfq_status,open_rfq_session, theRfqSessionmethods) raisesNotSupportedOnPaper("RFQ quoting is not simulated in PolySimulator paper mode."). Paginatordataframe exports —.to_pandas/.to_polars/.to_arrow(they need pandas/polars/pyarrow) are not shipped; the paginator's.first_page()/.iter_items()/ iteration surface is here.
Because the real py-sdk is a superset, the swap to real Polymarket only ever adds these — it never breaks a bot that stuck to the implemented surface.
Fidelity gaps within the implemented surface
A handful of implemented methods are present but narrower than py-sdk's. None break the prefix swap (the field names and call shapes match), but a bot that relies on the listed behaviour will see more on real Polymarket than the mirror provides:
Marketis a focused subset. The mirror'sMarketcarries only the identity fields (id,condition_id,question,slug) plus a focused nested.state(active/closed/neg_risk). py-sdk'sMarketis a deeply-nested gamma model — theoutcomes, per-outcomeprices, and themetrics/volume/liquidityblocks are not present here, andmarket.stateomits py-sdk's wider fields (archived,accepting_orders,enable_order_book,start_date/end_date/closed_time). The mirror also does not hex-validatecondition_idand does not reject non-binary markets the way py-sdk'sMarketmodel does — a payload py-sdk would raiseUnexpectedResponseErroron may bind here. Read only the focused identity+state subset for a clean swap; the rest lands whenMarketwidens.list_marketsaccepts py-sdk's full gamma keyword set but only forwards a few. Only the filters PolySimulator'sGET /v1/marketshonours (closed,order→sort,ascending) reach the server; every other gamma keyword (liquidity_num_min/max,volume_num_min/max,tag_id,clob_token_ids,question_ids,start_date_*/end_date_*, …) is accepted for signature parity and silently ignored. The call won't error, but the result set is not filtered by an ignored knob. (On real Polymarket every one of these filters applies server-side.)get_last_trade_pricealways reports sideBUY. PolySim's book snapshot carrieslast_trade_pricebut no trade side, so the mirror fills py-sdk's requiredsidefield with a constant"BUY". Don't branch on the last-trade side against the mirror — it isn't real provenance; on Polymarket it reflects the actual maker/taker side.Decimalstring-form (trailing zeros) may differ. The mirror computes prices from PolySim's/v1/bookand quantises to the 4-decimal grid, so a midpoint/price/spread can render asDecimal("0.5000")where py-sdk's server-computed value rendersDecimal("0.5"). The numeric value is equal (==and arithmetic match — the behavioural-parity suite asserts this), butstr(value)andvalue.as_tuple()can differ in trailing zeros. Compare by numeric value, never by string form, for a clean swap.0is the no-quote sentinel. When a token's book has no two-sided quote,get_midpoint/get_price/get_spreadreturnDecimal("0")(py-sdk's "no value available" sentinel) rather thanNoneor an error. A genuine0and a missing quote are indistinguishable — treat a0result as "no quote", not as a real price of zero.
Realtime streams (v2 mirror)
The async clients mirror py-sdk's subscribe() for the CORE stream topics,
backed by our polysim_sdk WS + SSE transport. A consumer iterates a
SubscriptionHandle and closes it (or uses it as an async context manager):
from polysim_polymarket import AsyncSecureClient
from polysim_polymarket.streams import MarketSpec, CryptoPricesSpec, UserSpec
async with await AsyncSecureClient.create(api_key="ps_live_…") as client:
async with await client.subscribe(MarketSpec(token_ids=["…"])) as h:
async for ev in h: # MarketPriceChangeEvent / MarketLastTradePriceEvent
print(ev.payload.market, ev.type)
The stream surface lives in polysim_polymarket.streams (the specs, the event
types, SubscriptionHandle) — exactly as py-sdk keeps it in
polymarket.streams. Neither package promotes any stream name to its package
root, so nothing stream-related is re-exported from polysim_polymarket (the
re-export subset is empty by design).
CORE topics → transport. Each topic maps to one polysim_sdk stream:
| Spec | Topic | Events emitted | Transport |
|---|---|---|---|
MarketSpec |
market |
MarketPriceChangeEvent, MarketLastTradePriceEvent |
ws.aprices_stream (/v1/ws/prices) |
CryptoPricesSpec |
prices.crypto.{binance,chainlink} |
CryptoPricesBinanceEvent / CryptoPricesChainlinkEvent |
sse.aspot_stream (/prices/stream) |
UserSpec (secure only) |
user |
UserTradeEvent, UserOrderEvent |
ws.aexecutions_stream (/v1/ws/executions) |
subscribe() is async-only (the sync clients have no subscribe, mirroring
py-sdk). The handle is a bounded queue with drop-oldest backpressure: under a
slow consumer it drops the oldest events and counts the losses in
handle.dropped. Pass queue_size= (a mirror-only keyword) to size it.
Seams — documented, not fabricated. Because PolySimulator's push surface is leaner than Polymarket's, the mirror is explicit where a py-sdk field has no real provenance:
- Auth handshake (user stream). The
userfeed mints a short-lived WS JWT from the secure client's API key (ws_token()) and connects to the authenticated/v1/ws/executionschannel — so it's scoped to that one account. There is no per-subscription credential;UserSpec.markets, when set, is applied as a client-side filter in the adapter (the channel delivers all of the account's fills). MarketSpec.token_idsare the SDK'scondition_id:LABELtokens (the same formget_*and trading use) — not raw Polymarket numeric token ids. The prices WS subscribes bycondition_id, so the opener strips each token's:LABELsuffix (a generic last-colon split, so non-binaryUP/DOWNlabels strip correctly — not the binary-only_split_token), de-duplicates, and subscribes those condition ids. Each delivered frame carries per-outcome entries with alabel(Yes/No/Up/Down) and the Polymarket CLOB-numerictoken_id; that raw digit is a different namespace from the SDK token, so the adapter does not filter on it (it would match nothing). Instead the adapter derives each outcome's SDK tokenf"{condition_id}:{LABEL}"from the frame'smarket_id+ outcomelabeland both filters on and emits that — so aMarketSpecbuilt from the SDK's owncondition_id:LABELtokens (e.g.["0xCID:YES", "0xCID:NO"]) subscribes["0xCID"]AND receives correctly-filtered events for those outcomes, end to end. The emitted event'stoken_idis thecondition_id:LABELform a bot uses for reads/trading, never the backend CLOB digit. (A raw pm numeric token id is not a validMarketSpec.token_idhere.)- No
bookevent from the market stream./v1/ws/pricesis a top-of-book cache, not an L2 ladder feed — so the market stream emitsprice_changeandlast_trade_pricebut never a fullbookevent. (Callget_order_bookfor the ladder.) - Stream id fields are plain
str. Token / condition / order id fields on the stream-event models (token_id,market,id,taker_order_id, …) are plainstr, consistent with the mirror-wide id-typing decision — they are not py-sdk's hex-validatedTokenId/CtfConditionIdnewtypes, so no hex-shape validation is applied to ids arriving on the wire. - Custom-feature / lifecycle market events are defined for parity but never
emitted.
MarketBestBidAskEvent,NewMarketEvent,MarketResolvedEvent, andMarketTickSizeChangeEventare part of theMarketEventunion (so a ported bot's imports andmatch-on-typeresolve) but the paper stream produces none of them —MarketSpec(custom_feature_enabled=True)is accepted for signature parity and is otherwise inert. - Lean user frames, honest derivation. The backend fill frame carries
market_id+outcomebut no CLOB token/asset id, so the event'stoken_idis derived —f"{market_id}:{OUTCOME}", the SDK's canonical token convention (the inverse of_split_token, the same formget_*/trading use), not faked from the order id.id/taker_order_idkeep the fill's realorder_id(those are order ids). Remaining py-sdk fields the frame lacks get honest defaults: the order'soriginal_size==size_matched== the filledquantitywithorder_event_type="UPDATE",status="MATCHED". A fill missing itsoutcomeyields no event (no honest token could be built). last_trade_priceside + size are read from the frame top level. The prices producer stamps the most-recent trade'slast_trade_side/last_trade_sizeat the frame top level (not on the per-outcome entry, which carries only the trade price). The adapter reads them there and emits the real side — a SELL trade yieldsside="SELL", never a fabricatedBUY. If a frame ever lacks the top-level side, thelast_trade_priceevent is dropped rather than mislabeled.- Crypto topic routing is by exact source label. The Binance feed's wire
sourceispolymarket_rtds(withrelay_binanceas a fallback-relay label); Chainlink's ischainlink_rtds. The adapter routes by exact membership in those label sets —prices.crypto.binancereceives the live Binance ticks and Binance ticks never leak into aprices.crypto.chainlinksubscription.
DEFERRED topics. py-sdk's polymarket.streams also ships sports
(SportsSpec / SportsEvent), comments (CommentsSpec / CommentsEvent /
reactions), and prices.equity.pyth (EquityPricesSpec / EquityPricesEvent),
plus the RtdsSpec / StreamEvent aliases and the merged multi-spec
subscribe(Sequence[...]). None of those are shipped here — pass a single
CORE spec per subscribe() call. Because real py-sdk is a superset, the swap to
real Polymarket only adds them.
Migrating from py-clob-client
The import below is the v1 path (
py_clob_client).py-clob-client-v2(py_clob_client_v2) is a different package and is out of scope — see Polymarket compatibility above.
If you have a Polymarket bot, you change three things and delete the on-chain prelude. Everything else — method names, argument shapes, return shapes — stays.
- from py_clob_client.client import ClobClient
- from py_clob_client.clob_types import OrderArgs, OrderType
+ from polysim_clob_client.client import ClobClient
+ from polysim_clob_client.clob_types import OrderArgs, OrderType
- client = ClobClient(
- host="https://clob.polymarket.com",
- key=PRIVATE_KEY, # your wallet's private key
- chain_id=POLYGON,
- signature_type=1,
- funder=PROXY_WALLET_ADDRESS,
- )
- client.set_api_creds(client.create_or_derive_api_creds())
- # ...plus USDC allowance/approval txns, web3 setup, etc.
+ client = ClobClient(
+ host="https://api.polysimulator.com",
+ key="ps_live_…", # your PolySimulator API key
+ )
# unchanged from here on:
order = client.create_order(OrderArgs(token_id=tid, price=0.55, size=10, side="BUY"))
resp = client.post_order(order)
What maps how
Every method maps by one of three strategies:
- mirror — identical behaviour, delegated to the HTTP core.
- adapt — translated onto the PolySim REST surface (e.g.
get_midpoint,get_price,get_spreadare computed fromGET /v1/markets/{id}/book). - stub-noop — on-chain machinery with no analog (allowances, signing, scoring, builder auth). These return a benign canned value and make no network call; each says so in its docstring so nothing breaks silently.
token_id ↔ (market_id, outcome)
py-clob-client addresses a single outcome token by token_id; PolySimulator
addresses a market plus an outcome. The seam: a bare token_id is treated as
the market id with outcome YES. Append ":NO" or ":YES" to target the other
side explicitly. Up/Down markets carry Up/Down outcomes, so the same
colon form also accepts ":UP" / ":DOWN" (case-insensitive); the backend
matches the order outcome case-insensitively, so either case is accepted.
client.create_order(OrderArgs(token_id="0xMARKET", ...)) # → market 0xMARKET, YES
client.create_order(OrderArgs(token_id="0xMARKET:NO", ...)) # → market 0xMARKET, NO
client.create_order(OrderArgs(token_id="0xUPDOWN:UP", ...)) # → Up/Down market, UP
Reads are true-token-parity; writes use the market+outcome model. This is an intentional asymmetry:
- Book/quote reads —
get_order_book,get_midpoint,get_price,get_spread,get_tick_size,get_neg_risk,get_last_trade_price,calculate_market_price— send a baretoken_idto the token-native endpointGET /v1/book?token_id=.... This matches Polymarket's CLOB book reads exactly: pass the real outcome-token id you already use withpy-clob-clientand the quote comes back for that token, no:YES/:NOneeded. Thecondition_id:OUTCOMEcolon form still works and routes to the condition-id book endpoint (threading the outcome through), but it is a PolySimulator convenience extension, not the parity path. - Fee rate —
get_fee_rate_bps(token_id)readsGET /v1/fee-rateand returnsfee_rate_bps, the taker fee the matching engine actually charges on that market's category (e.g. crypto 700, sports 300, geopolitics 0; resting makers pay 0). It is not the PMbase_feeflag and it is not0: paper fills are charged fees. A condition id is resolved to one of the market's CLOB token ids first; the result is cached per token. - Order writes —
create_order/create_market_order/post_order— resolve thetoken_idthrough the market+outcome seam above and submit to the richPOST /v1/ordersendpoint (with slippage/impact/position telemetry in the response). A bare token id on the write path is read as amarket_idwith theYESoutcome; if that id isn't a valid market, the server rejects the order loudly — it never silently places a different one.
If you only ever pass real outcome-token ids (the py-clob-client norm), reads
"just work" with full parity. The :YES/:NO suffix (and :UP/:DOWN for
Up/Down markets) exists for callers who prefer to address PolySimulator markets
by condition id directly.
Orders are never signed
create_order / create_market_order return a plain dict with no
signature field — there is nothing to sign. post_order serialises it
straight to POST /v1/orders. The recommended one-call path is
create_and_post_order(...).
Auth assertions
The three py-clob-client auth levels collapse into one. assert_level_1_auth()
and assert_builder_auth() are no-ops; assert_level_2_auth() raises
PolyApiException only if no API key is configured.
Pagination
The native client exposes Python iterators that page transparently:
from polysim_sdk import PolySimClient
from polysim_sdk.pagination import iter_markets, iter_orders
with PolySimClient() as client:
for market in iter_markets(client, hot_only=True):
...
for order in iter_orders(client, status="OPEN"):
...
The drop-in surface preserves py-clob-client's base64 cursor protocol, so the
classic loop terminates correctly:
from polysim_clob_client.constants import END_CURSOR
cursor = ""
while cursor != END_CURSOR:
page = client.get_markets(cursor)
handle(page["data"])
cursor = page["next_cursor"]
WebSocket streaming
from polysim_sdk import PolySimClient
from polysim_sdk.ws import prices_stream, executions_stream
with PolySimClient() as client:
for event in prices_stream(client, ["0xMARKET_A", "0xMARKET_B"]):
print(event) # blocks; reconnects with a fresh token + backoff
Async generators (aprices_stream, aexecutions_stream) are available for
async for. The SDK mints a short-lived WS JWT per connection automatically.
Every reconnect waits out a capped exponential back-off (0.5 s, doubling to
30 s, reset once a connection has stayed up for 10 s) and counts against
max_reconnects= (default None: never give up). That covers a socket error,
a clean close by the server, and a token mint that failed with 429, 5xx or a
network error. When the budget is spent the last error is raised, or the stream
simply ends if the server had closed cleanly. A 401 / 403 from the token
mint (bad or revoked key) raises at once.
SSE: live underlying spot
The WS channel above carries market prices. The live underlying spot
(BTC/ETH/SOL/… ticks — the number an Up/Down bet resolves against) comes from the
public, unauthenticated /prices/stream Server-Sent-Events firehose instead:
from polysim_sdk import PolySimClient
from polysim_sdk.sse import spot_stream
with PolySimClient() as client:
for event in spot_stream(client, ["BTC", "ETH"], crypto_source="chainlink"):
if event["event"] == "crypto_price":
tick = event["data"]
print(tick["symbol"], tick["price"], tick["source"])
Each event is {"event": <type>, "data": <payload>}. The spot-bearing types are
crypto_price and crypto_price_batch; keepalive arrives every ~5 s. Pass
crypto_source="chainlink" (authoritative for 5m/15m settlement) or "binance"
(denser ~10 Hz ticks); omit for both. With condition_ids=[...] the same stream
also delivers snapshot / market_price / orderbook events. The async twin
aspot_stream is available for async for.
Reconnects follow the WebSocket rules above: every reconnect, a clean close by
the server included, counts against max_reconnects= and waits out a jittered
back-off (0.5 s doubling to 30 s, reset once a connection has stayed up for
10 s). A wait the server names is a floor: Retry-After on a 429/503, the
retry_after of an event: error frame, or the SSE retry: field. One longer
than max_retry_after raises instead, with the server's wait in
exc.retry_after: RateLimitError for a 429, an error frame or a retry:
field (checked when a reconnect would apply it), the status's own ApiError
for a 503. A reconnect re-opens the same
subscription with a fresh cache-buster (so a CDN can't coalesce subscribers),
and the server re-seeds it with a new snapshot; missed ticks are not
replayed. If the server tags events with an SSE id:, the last one is sent
back as Last-Event-ID.
Errors
Catch PolySimError to handle every SDK-raised error; PolyApiException (the
drop-in alias) is the same class.
from polysim_sdk.exceptions import (
EdgeBlockedError,
OutcomeUnknownError,
PolySimError,
RateLimitError,
ValidationError,
)
try:
fill = client.place_order(...)
except RateLimitError as exc:
print(f"backing off for {exc.retry_after}s")
except ValidationError as exc:
print(f"bad request: {exc.code} → {exc}")
except EdgeBlockedError as exc:
print(f"blocked at the CDN edge — check your User-Agent: {exc}")
except PolySimError as exc:
print(f"other API error ({exc.status_code}): {exc}")
try:
key = client.create_key(name="bot-2")
except OutcomeUnknownError:
# Timed out after the request may have reached the server: look before
# trying again, or you may end up with two keys.
existing = client.list_keys()
Pacing. The client paces itself to the rate limit the server reports.
Until the first response it keeps a 50 ms floor between requests; once a
response carries X-RateLimit-Limit-Per-Second, request starts are spaced to
stay under it (a free key's 2 req/s: one request every 0.55 s). When
X-RateLimit-Remaining (the per-minute allowance) reaches 0, the next request
waits for X-RateLimit-Reset instead of spending a 429 on the closed window.
Pass pace_from_headers=False to keep only the floor, or
floor_interval=0.0, pace_from_headers=False, max_retries=0 to handle pacing
and retries yourself.
Retries. 429 waits out Retry-After; 425, 502, 503 and 504 back
off exponentially (1 s, 1.5 s, 2.25 s; a 500 is not retried); transport
errors back off from 0.5 s. Every
wait is jittered so clients that failed together do not retry together; a
Retry-After is a floor the jitter only adds to.
Retries never repeat a write the server cannot dedupe. A read timeout, a
dropped connection or a 502/503/504 can arrive after the server already
applied the request. Reads, DELETEs and the writes the server dedupes on their
Idempotency-Key (place_order, place_orders, split_position,
merge_positions, simulation.create_backtest) are retried through these, with
the same key on every attempt. create_key, rotate_key, bootstrap,
create_wallet, reset_wallet, reset_api_balance and cancel_all are not:
they raise OutcomeUnknownError (an ApiError, code="OUTCOME_UNKNOWN") so you
can check the state before calling again. Failures that never reached the
server (connection refused, 425, 429) are retried for every call. Every
write sends an Idempotency-Key.
The client will not sleep longer than max_retry_after seconds (default 60)
on one Retry-After. A 429 that asks for more raises RateLimitError
immediately, with exc.retry_after set to the server's value, so a long
server-side wait never blocks a call silently. Pass max_retry_after=None to
restore unlimited waiting.
New-market warm-up 404 (retry-on-404)
The SDK auto-retries 429/5xx but never a 404 — a 404 is normally
permanent. The one benign exception is a freshly-created market (most often
a 5m Up/Down window): for a short window after creation — on the order of ~30s,
the Up/Down roll cadence, though not a guarantee — it is not yet in the
order-validation catalog and order placement transiently fails with
ApiError(status_code=404, code="MARKET_NOT_FOUND"). Retry only that signal,
with backoff; re-raise any other error (including a 404 with a different code,
which is a real "not found").
Use the shipped helper (recommended) …
from polysim_sdk import PolySimClient, retry_on_market_warmup
with PolySimClient() as client:
fill = retry_on_market_warmup(
lambda: client.place_order(
market_id=cid, side="BUY", outcome="Up", amount="10", price="0.99",
),
attempts=6, base_delay=2.0,
)
… or roll your own on the native ApiError:
import time
from polysim_sdk import ApiError
for i in range(6):
try:
fill = client.place_order(market_id=cid, side="BUY", outcome="Up",
amount="10", price="0.99")
break
except ApiError as exc:
if exc.status_code == 404 and exc.code == "MARKET_NOT_FOUND" and i < 5:
time.sleep(min(2.0 * 2**i, 30.0)) # capped backoff, then retry
continue
raise # any other error — and the final 404 — propagates
With the polysim_clob_client drop-in, the same condition surfaces as a
PolyApiException with status_code == 404; catch it and retry the same way (or
pass your drop-in call to retry_on_market_warmup(lambda: clob.create_and_post_order(...)),
which works with any callable):
from polysim_clob_client.exceptions import PolyApiException
try:
resp = clob.create_and_post_order(order_args)
except PolyApiException as exc:
if exc.status_code == 404 and getattr(exc, "code", None) == "MARKET_NOT_FOUND":
... # warm-up — retry with backoff
else:
raise # any other error — including a 404 with a different code — propagates
Troubleshooting: error code: 1010 / blocked User-Agent
If a raw HTTP call returns HTTP 403 with the body error code: 1010, the
request was blocked at the CDN edge — not by the API. The edge rejects
Python's stdlib urllib default User-Agent (Python-urllib/x.y). requests,
httpx, aiohttp, and this SDK all send User-Agents that pass, so you only
hit this with raw urllib or a custom client that forwards the stdlib UA.
This SDK sends a branded User-Agent: polysim-sdk/<version> and turns any edge
block into a clear EdgeBlockedError (an ApiError, code="EDGE_BLOCKED"). If
you must call the API without the SDK, set your own header:
# raw urllib — set a User-Agent so the edge lets you through
import urllib.request, json
req = urllib.request.Request(
"https://api.polysimulator.com/v1/markets?limit=1",
headers={"User-Agent": "my-app/1.0", "X-API-Key": "ps_live_..."},
)
data = json.load(urllib.request.urlopen(req))
Rate limits
Authoritative values are returned live by GET /v1/keys/tiers (client.tiers()).
At the time of writing:
| Tier | rps | rpm | WS conns | Batch | API balance |
|---|---|---|---|---|---|
| Free | 2 | 120 | 1 | 1 | $100, one-time (no reset) |
| Pro | 30 | 1800 | 3 | 5 | $10K |
| Pro+ | 60 | 3600 | 10 | 10 | $25K |
| Enterprise | 100 | 6000 | 50 | 25 | custom |
free allows 2 requests/second up to 120/minute, one WebSocket connection and a
batch size of 1. Free keys issued on or after 2026-09-05 can trade (read +
trade) against a one-time $100 API wallet: reset_api_balance() is refused
with 402 UPGRADE_REQUIRED on free. Free trading is also capped at 100 orders
per UTC day per account, across all of its keys; past that, orders get a 429
whose Retry-After runs to the next UTC midnight. The SDK does not sleep on a
wait that long: it raises RateLimitError with retry_after set to it (see
max_retry_after under Errors). Free keys issued before 2026-09-05
stay read-only. Use pro or above for any continuously-running bot. The table
is illustrative — always trust client.tiers() for the live values.
You do not need to hard-code these limits: the client reads them from the
X-RateLimit-* headers on every response and paces itself (see Pacing
under Errors). The limiter counts fixed clock-second and
clock-minute windows, rejected requests included, so a loop that ignores a
429 only digs deeper.
Beta caveats
During the open beta, a few sim behaviours differ from Polymarket. These are known limitations, not bugs:
- Shared API balance across keys. Every key a user owns draws on the same
balance pool today (the
balancefield returned byme()). Treat it as user-scoped, not key-scoped. - Maker/taker classification. A marketable-at-placement GTC (one that
crosses the book on submit) is classified as a taker and charged the taker
fee, matching Polymarket; only a genuinely-resting GTC that is filled later —
when the market moves into it — is booked as a $0-fee maker. The realized
per-fill fee rate is surfaced as
ClobTrade.fee_rate_bps(the realized fee amount is not a typed field). - Orderbook freshness. The book cache TTL is 300 s. For markets Polymarket updates less often than that, a fill may revert to displayed midpoint; a ±15% sanity guard bounds the drift. High-volume markets always fill at real ask/bid.
What's included
The PyPI package ships the three import packages. The example scripts and the test suite live in the source repository.
| Path | Purpose |
|---|---|
polysim_sdk/ |
Native client: PolySimClient (sync) + AsyncPolySimClient (async), ws, sse (underlying-spot stream), updown (Up/Down row helpers), pagination, exceptions, constants. |
polysim_clob_client/ |
py-clob-client drop-in: ClobClient + matching clob_types, constants, order_builder, exceptions. |
polysim_polymarket/ |
Unified py-sdk (polymarket) paper-mode mirror: sync + async PublicClient / SecureClient (CLOB reads, account/auth, trading), on-chain paper no-ops, rewards/builder/RFQ stubs, and core realtime streams — returning typed pydantic models. See Polymarket py-sdk (v2) mirror. |
scripts/01_balance_and_market.py |
Smallest end-to-end native demo. |
scripts/02_clob_dropin_demo.py |
The py-clob-client drop-in surface end-to-end. |
scripts/03_async_concurrent.py |
Concurrent reads via the async client. |
scripts/04_btc_updown.py |
Discover the live BTC Up/Down window: spot, strike, prices, tokens. |
tests/ |
respx-mocked unit tests for both surfaces (no creds, no network). |
Run the test suite with pytest. Lint/type with ruff check . && mypy polysim_sdk polysim_clob_client polysim_polymarket.
License
Apache License 2.0. You may use, modify, and redistribute this
SDK — including in commercial and closed-source projects — provided you keep
the license and attribution notices (see NOTICE). Apache-2.0 also
grants an explicit patent license, which is why many companies prefer it over
MIT for dependencies.
The polysim_clob_client package mirrors the public surface of
py-clob-client (MIT) for
drop-in compatibility; no upstream source is bundled. This project is not
affiliated with or endorsed by Polymarket.
Metadata
Release files for polysimulator 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polysimulator-0.8.0.tar.gz | 249.4 kB | Without provenance | Details for polysimulator-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polysimulator-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for polysimulator-0.8.0-py3-none-any.whl |
Total release size: 501.7 kB
Release files / polysimulator-0.8.0.tar.gz
| Download URL | polysimulator-0.8.0.tar.gz |
|---|---|
| Size | 249.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4cf9607e7d7f897880157cf263723840959ba8c90b998a4674b7d4acd61e323
|
|
BLAKE2b-256 checksum How to use checksums |
85253b7ff23bd05cca5316a897d9622a5c5dc664e28ea1687f87bd690b0f5f77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / polysimulator-0.8.0-py3-none-any.whl
| Download URL | polysimulator-0.8.0-py3-none-any.whl |
|---|---|
| Size | 252.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0730ba9134b49db94d2ec06c8bccf548f2adcab86571971047d2c0b58475565d
|
|
BLAKE2b-256 checksum How to use checksums |
b1d7433dd8c36418b96dc4b2caeff8e6af998211a0ccf443f3d71b3001afa46c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for polysimulator 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.