Who this is for. Programmatic API partners with a server-wallet sub-account. Endpoints require a scoped API token with the
trading and delegated_signing scopes. See Programmatic API to get access and create a sub-account.When to use these endpoints
Use AMM endpoints when the market is an FPMM AMM market (single-outcome buy/sell against a pool). Use the CLOB order endpoints for order-book markets. If you’re unsure which type a market uses, fetch it withGET /markets/{slug} and inspect the market metadata.
All four endpoints are HMAC-authenticated. See HMAC request signing for the signing protocol.
Prerequisites
- A scoped API token with both
tradinganddelegated_signingscopes. Derive one viaPOST /auth/api-tokens/derive. - A server-wallet sub-account. Create one with
createServerWallet: trueviaPOST /profiles/partner-accounts. - Enough collateral (for buys) or outcome-share balance (for sells) on the server wallet.
- A one-time approval per market and side (see Allowances).
Amount conventions
All amounts are positive integer strings in the market collateral token’s base units (for USDC this means 6 decimals:"1000000" = 1 USDC).
Slippage is expressed in basis points:
- Default
slippageBps:100(1%) - Maximum:
1000(10%) - Applied against the on-chain quote at request time — the server rejects trades whose quoted price moves beyond the bound
Buying outcome shares
POST /amm/buy spends a fixed amount of collateral on a chosen outcome. The server fetches a fresh on-chain quote, applies your slippage bound, and submits a sponsored user operation from the sub-account’s server wallet.
Request
Example
Response — 201 Created
expectedShares— shares expected at the current quoteminShares— floor after applyingslippageBpstxHashmay be absent immediately after submission for sponsored user operations; usetransactionIdoruserOperationHashto track completion
Selling outcome shares
POST /amm/sell targets an exact collateral return, bounded by the maximum shares you’re willing to spend to achieve it. The server quotes the required shares, applies your slippage tolerance in the opposite direction, and submits.
Request
Example
Response — 201 Created
expectedShares— shares required at the current quote to receivecollateralReturnAmountmaxShares— cap after applyingslippageBps; the trade fails on-chain if it would require more
Allowances
Every server wallet needs a one-time approval per market and side:- Buy: the AMM must be approved to pull collateral (ERC20
approve). - Sell: the AMM must be approved as an operator for outcome shares (ERC1155
setApprovalForAll).
Check allowance — POST /amm/allowances/check
Reads the current on-chain state.
statusisconfirmedwhen the on-chain allowance is at or above the ready threshold, otherwisemissing.currentAllowanceis only returned forBUY(ERC20) —SELLuses the booleanisApprovedForAllon ERC1155.
Submit approval — POST /amm/allowances/approve
Same request body as check. Behavior:
- If the allowance is already
confirmedon-chain, the endpoint returns200 OKwithstatus: "confirmed"and no transaction. - If the server submits a new approval, the endpoint returns
202 Acceptedwithstatus: "submitted"and Privy transaction identifiers. The approval is asynchronous; poll/amm/allowances/check(or wait a few seconds) before submitting the trade.
Idempotency and retries
idempotencyKey is required on /amm/buy and /amm/sell so that network hiccups and client retries never double-submit a trade.
- Keys are scoped to the target profile and retained for 24 hours.
- Reusing the same key with the same trade parameters returns the original submitted result — safe to retry after a timeout.
- Reusing the same key with different parameters returns
409 Conflict. - Keys must contain at least one non-whitespace character and be at most 128 chars long.
"{internal-trade-id}") so a lost response does not force a duplicate trade.
Rate limits
AMM endpoints share a per-caller limit of 10 requests per 10 seconds. Excess calls return429 Too Many Requests with a retryAfterSeconds field. The bucket key is the API token, actor profile, or wallet — whichever is available on the request.
Error responses
Redeeming resolved AMM positions. Once a market resolves, claim payouts through the existing
POST /portfolio/redeem endpoint. It accepts the same onBehalfOf convention and requires the trading scope for API-token callers.Typical flow
1
Verify the server wallet has collateral
Use your own accounting or
GET /portfolio/positions with x-on-behalf-of set to the sub-account.2
Ensure the allowance is confirmed
Call
POST /amm/allowances/check. If status is missing, call POST /amm/allowances/approve and wait for confirmation.3
Submit the trade
Call
POST /amm/buy or POST /amm/sell with an idempotencyKey your system can regenerate on retry.4
Track submission
Use the returned
transactionId and userOperationHash to correlate with your accounting. Retry the exact same request if the response is lost — the idempotency key guarantees at-most-once execution.