Overview
TheOrderClient handles order creation, EIP-712 signing, and order management. It supports Good-Til-Cancelled (GTC), Fill-And-Kill (FAK), and Fill-or-Kill (FOK) orders.
Prerequisites
Before placing orders, you need four components:The
OrderClient constructor automatically fetches your user profile data (userData) from the API. This is used to populate the ownerId field on submitted orders.Token approvals
Before your first trade on a given venue, you must approve the exchange contracts to spend your tokens. This is a one-time on-chain setup per venue.- Standard CLOB
- NegRisk
For standard CLOB markets, approve USDC and Conditional Tokens to the exchange contract:
GTC orders (Good-Til-Cancelled)
GTC orders remain on the orderbook until filled or explicitly cancelled. Specifyprice (in dollars) and size (number of shares):
Post-only GTC order
Usepost_only=True to ensure your order is never filled immediately as a taker. If the order would cross the spread (i.e., match against existing orders), it is rejected instead. This guarantees you always receive maker fees.
Self-trade prevention
Passstp_policy to control what happens when your incoming order would match your own resting order on the same token. It is a top-level request field — not part of the EIP-712 signed order — and applies to any order type. Omit it to keep the server default, cancel_maker.
The create-order response carries an
execution object with the outcome:
Self-trade prevention blocks same-profile matches on the same token only. Orders on a different token of the same profile are unaffected. The wire field is always
stpPolicy, regardless of the SDK.FAK orders (Fill-And-Kill)
FAK orders use the sameprice and size inputs as GTC, but they only consume immediately available liquidity and cancel any unmatched remainder.
post_only is not supported for FAK orders.
FOK orders (Fill-or-Kill)
FOK orders execute immediately and fully, or are rejected entirely. Instead ofprice and size, you specify maker_amount:
- FOK BUY
- FOK SELL
When buying,
maker_amount is the total USDC you want to spend. The exchange fills as many shares as possible at the best available price:AMM trading
CLOB orders trade against the orderbook. AMM (FPMM) markets trade against a pool, and the SDK exposes them throughclient.partner_amm. The service calls POST /amm/allowances/check, POST /amm/allowances/approve, POST /amm/buy, and POST /amm/sell on behalf of a partner server wallet.
Use it when the market is an AMM market and you want the server to hold custody, sign the trade, and pay gas. See AMM Trading (Server Wallets) for the underlying endpoints and market model.
Requirements
- Authenticate with an HMAC API token that holds both the
tradinganddelegated_signingscopes, or pass a per-call Privyidentity_token. Legacyx-api-keycredentials are rejected. - The trade runs against a server-wallet sub-account. Set
on_behalf_ofto the sub-account profile ID, or omit it to trade from the authenticated profile. - Amounts are positive integer strings in the collateral token’s base units (for USDC:
"1000000"= 1 USDC). Never pass floats. slippage_bpsis optional and ranges from0to1000. The server default is100(1%).outcome_indexis0for YES and1for NO.
One-time approval per wallet and market
BUY and SELL approvals are independent and set up once per wallet and market. buy and sell do not preflight allowances themselves. Confirm the allowance first.
ensure_allowance runs check_allowance, submits approve_allowance at most once when missing, then polls the check until confirmed is true. Tune the poll with interval (default 2 seconds) and max_attempts (default 30).
A
submitted response from approve_allowance (HTTP 202) is not confirmation. Either use ensure_allowance, or poll check_allowance until confirmed is true.Buy shares
buy spends an exact collateral amount on the chosen outcome. Pass a unique idempotency_key per trade. On a timeout retry, reuse the exact same params so the server replays the original submission rather than opening a second trade.
Sell shares
sell requests an exact collateral return by selling outcome shares.
Reusing an
idempotency_key with different params raises ConflictError (HTTP 409). The four AMM routes share a rate limit of 10 requests / 10 seconds per actor. Pass with_raw_response=True to any AMM method to receive an HttpRawResponse exposing status, headers, and data.Cancelling orders
- Cancel a single order
- Cancel all orders on a market
Cancel a specific order by its ID:
Cancel and replace
cancel_replace cancels one open order and submits a replacement in the same request. Use it to reprice or resize a resting order in one round-trip instead of separate cancel and create calls. cancel_replace_batch runs several of these operations in a single call.
The cancel and the replacement are not atomic: they report independent outcomes, and a successful cancel does not guarantee a successful replacement. Choose the failure mode with CancelReplaceMode:
Identify the order to cancel by exactly one of
order_id or client_order_id. The replacement is a normal signed order and uses the same fields as create_order (order_type, market_slug, token_id, side, price, size or maker_amount, post_only, stp_policy, etc.).
Single cancel-replace
Batch cancel-replace
Each operation is a dict of the same keyword arguments accepted bycancel_replace. Results come back with the caller’s index:
Delegated cancel-replace
Partners with thedelegated_signing scope call delegated_order_service.cancel_replace and .cancel_replace_batch. The server signs the replacement using the sub-account’s managed wallet, so no private key is required. Pass on_behalf_of (the sub-account profile ID) on every operation:
See
POST /orders/cancel-replace and POST /orders/cancel-replace/batch for the full request and response shapes, per-status fields, and failure semantics.Enums reference
Side
OrderType
Error handling
The SDK raisesAPIError for non-2xx responses. Always wrap order calls in try/except:
See Error Handling & Retry for details on
APIError fields and the @retry_on_errors decorator.