Skip to main content

Overview

The Rust SDK provides OrderClient for order creation, EIP-712 signing, and order management. It supports:
  • OrderType::Gtc for resting limit orders
  • OrderType::Fak for fill-and-kill limit orders
  • OrderType::Fok for fill-or-kill market orders

Prerequisites

Before placing orders, you need:
  • an authenticated Client
  • a private key for EIP-712 signing
  • market venue data (fetched via get_market() and cached automatically)
The OrderClient lazily fetches your profile on the first order to determine your owner_id and fee rate. CHAIN_ID defaults to 8453 (Base mainnet) unless you override it.
Wallet-mode preflight. Accepting the one-time “choose your trading wallet” prompt in the app enables 1-click (smart wallet) trading on your Limitless profile. Once that mode is set, self-signed orders are rejected with Signer does not match - you should use embedded address for smart wallet. Switch the profile to EOA trading mode first: see Trading wallet mode.

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.
Approve USDC and Conditional Tokens to the exchange contract:
Approvals are on-chain transactions that cost gas. Use venue.exchange for both CLOB and NegRisk, and additionally venue.adapter for NegRisk markets.

GTC orders

GTC orders remain on the book until filled or explicitly cancelled.

Post-only GTC order

Use post_only: true to ensure the order never crosses the spread as a taker:

GtcOrderArgs

Self-trade prevention

Set stp_policy on CreateOrderParams 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 args — and applies to any order type. Leave it None to keep the server default, cancel_maker.
The create-order response carries an execution field 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

FAK orders use the same price + size inputs as GTC, but any unmatched remainder is cancelled immediately.
post_only is not supported for FAK orders.

FOK orders

FOK orders execute immediately and fully, or are cancelled entirely. Instead of price and size, you pass maker_amount.
For buys, maker_amount is the total USDC to spend:

FokOrderArgs

Build and sign separately

For advanced flows, build and sign orders without submitting them:
You can also override the signing config explicitly:

AMM trading

CLOB orders trade against the orderbook. AMM (FPMM) markets trade against a pool, and the SDK exposes them through sdk.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 trading and delegated_signing scopes, or call the *_with_identity variants with a Privy identity token. Legacy x-api-key credentials are rejected.
  • The trade runs against a server-wallet sub-account. Set on_behalf_of to the sub-account profile ID (1..=2147483647), or leave it None to trade from the authenticated profile.
  • Amounts are positive integer strings in the collateral token’s base units (for USDC: "1000000" = 1 USDC). Never use floats.
  • slippage_bps is Option<u32>. None uses the server default of 100 (1%); values range from 0 to 1000.
  • outcome_index is 0 for YES and 1 for 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. Configure the poll via AmmAllowancePollOptions (default 2s interval, 30 attempts).
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. Every AMM method has a *_with_raw sibling (e.g. sdk.amm.buy_with_raw) that returns SdkResponse<T> with the HTTP status, headers, and body.

Cancelling orders

Cancel a single order:
Cancel all orders in a market:

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 with CancelTarget::OrderId or CancelTarget::ClientOrderId. The replacement uses the same OrderArgs fields as create_order.

Single cancel-replace

Batch cancel-replace

Each operation runs independently and its result is returned with the caller’s index:

Delegated cancel-replace

Partners with the delegated_signing scope call delegated_orders.cancel_replace and delegated_orders.cancel_replace_batch. The server signs the replacement using the sub-account’s managed wallet, so no signing key is required. Set on_behalf_of (the sub-account profile ID) and fee_rate_bps 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.