Overview
TheOrderClient handles order creation, EIP-712 signing, and order management. It supports Good-Till-Cancelled (GTC), Fill-And-Kill (FAK), and Fill-or-Kill (FOK) orders.
Prerequisites
Before placing orders, you need three components:The
OrderClient lazily fetches your user profile on the first order to determine your fee rate. The CHAIN_ID environment variable defaults to 8453 (Base mainnet).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-Till-Cancelled)
GTC orders remain on the orderbook until filled or explicitly cancelled. SpecifyPrice (0.0–1.0, tick-aligned to 0.001) and Size (number of 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.
GTCOrderArgs
Self-Trade Prevention
SetStpPolicy 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 empty 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 (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.
FAKOrderArgs
FOK Orders (Fill-or-Kill)
FOK orders execute immediately and fully, or are rejected entirely. Instead ofPrice and Size, you specify MakerAmount:
- FOK BUY
- FOK SELL
When buying,
MakerAmount is the total USDC you want to spend (max 6 decimal places). The exchange fills as many shares as possible at the best available price:FOKOrderArgs
Advanced: Build and Sign Separately
For advanced use cases, you can build and sign orders without submitting them:Cancelling Orders
- Cancel a single order
- Cancel all orders on a market
Cancel a specific order by its ID:
Enums Reference
Side
OrderType
Error Handling
The SDK returns typed errors for order failures. Useerrors.As() to inspect them:
See Error Handling & Retry for details on error types and the
WithRetry function.