Skip to main content

Overview

The OrderClient 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 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.
For standard CLOB markets, approve USDC and Conditional Tokens to the exchange contract:
Approvals are on-chain transactions that cost gas. You only need to perform them once per venue. Use venue.exchange for both CLOB and NegRisk, and additionally venue.adapter for NegRisk markets.

GTC Orders (Good-Till-Cancelled)

GTC orders remain on the orderbook until filled or explicitly cancelled. Specify price (in dollars) and size (number of shares):

Post-only GTC order

Use post_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

Pass stp_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 same price 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 of price and size, you specify maker_amount:
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:

Cancelling Orders

Cancel a specific order by its ID:

Enums Reference

Side

OrderType

Error Handling

The SDK raises APIError 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.

Complete Example

Always call await http_client.close() when finished. Failing to close the client can leave open connections and cause resource leaks.