Prerequisites
Before placing orders, initialize the required clients:OrderClient constructor
The
OrderClient automatically fetches your user profile data (including ownerId) from the API on the first order. You do not need to supply it manually.Token approvals
Before trading, your wallet must approve the relevant venue contracts to spend USDC and conditional tokens. This is a one-time setup per venue.Approval requirements
Manual approval with ethers
GTC orders (Good-Til-Cancelled)
GTC orders remain on the orderbook until filled, cancelled, or the market resolves. Specifyprice (probability between 0 and 1) and size (number of shares).
Buy YES shares
Post-only GTC order
UsepostOnly: 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.
Sell NO shares
GTC parameter reference
Self-trade prevention
PassstpPolicy 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.
postOnly is not supported for FAK orders.
Buy with FAK
Sell with FAK
FAK parameter reference
FOK orders (Fill-or-Kill)
FOK orders execute immediately against the existing orderbook or are rejected entirely. Instead ofprice and size, specify makerAmount which represents the total value to trade.
Buy with FOK
For a BUY FOK order,makerAmount is the amount of USDC you are willing to spend:
Sell with FOK
For a SELL FOK order,makerAmount is the number of shares you want to sell:
FOK parameter reference
NegRisk orders
When trading NegRisk markets, always use the submarket slug. The group slug is not tradeable. Fetch the group to discover submarkets, then fetch the specific submarket to get its token IDs.AMM trading
CLOB orders trade against the orderbook. AMM (FPMM) markets trade against a pool, and the SDK exposes them throughclient.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 PrivyidentityToken. Legacyx-api-keycredentials are rejected. - The trade runs against a server-wallet sub-account. Set
onBehalfOfto 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. slippageBpsis optional and ranges from0to1000. The server default is100(1%).outcomeIndexis0for 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.
ensureAllowance runs checkAllowance, submits approveAllowance at most once when missing, then polls the check until confirmed is true. Tune the poll with intervalMs (default 2000) and maxAttempts (default 30).
A
submitted response from approveAllowance (HTTP 202) is not confirmation. Either use ensureAllowance, or poll checkAllowance until confirmed is true.Buy shares
buy spends an exact collateral amount on the chosen outcome. Pass a unique idempotencyKey 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
idempotencyKey with different params raises ConflictError (HTTP 409). The four AMM routes share a rate limit of 10 requests / 10 seconds per actor. Pass { withRawResponse: true } to any AMM method to receive an SdkResponse with HTTP status and headers.Cancelling orders
Cancel an open order by its ID:Cancel and replace
cancelReplace 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 rather than issuing separate cancel + create calls. cancelReplaceBatch runs several of these operations in a single call.
The two actions are not atomic: the cancel and the replacement have 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
orderId or clientOrderId. The replacement is a normal signed order and accepts the same fields as createOrder (orderType, marketSlug, tokenId, side, price, size or makerAmount, postOnly, stpPolicy, etc.).
Single cancel-replace
Batch cancel-replace
Each entry runs independently and its result is returned with the caller’sindex:
Delegated cancel-replace
Partners with thedelegated_signing scope call client.delegatedOrders.cancelReplace and client.delegatedOrders.cancelReplaceBatch. The server signs the replacement using the sub-account’s managed wallet, so no private key is required. Set onBehalfOf to 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.Order states
Error handling
The SDK throwsAPIError for HTTP-level failures. Inspect status and message for details.
Validation rules
Price validation
Price validation
Prices must be between 0 and 1 (exclusive). A price of
0.65 means you value the outcome at 65%. Prices outside this range will be rejected by the API.Size validation
Size validation
Size must be a positive number. Fractional sizes are allowed if they align to the shares step (0.001). Max 3 decimal places.