OrderBookApi
Overview
TheOrderBookApi class provides direct access to CoW Protocol OrderBook endpoints, handling quotes, order submission, retrieval, cancellations, and trading data with built-in rate limiting and error handling.
Installation
Core Functionality
Quote Management
ThegetQuote() method retrieves pricing information before order submission, accepting parameters like sell/buy tokens, order kind (sell or buy), and price quality preferences.
Order Operations
sendOrder()- Submit signed orders to the order bookgetOrder()- Retrieve order details by unique identifiergetOrders()- Fetch all orders for a specific account ownergetOrderMultiEnv()- Check both production and staging environments
Cancellations
ThesendSignedOrderCancellations() method performs soft cancels that may not prevent execution if already processing.
Trading Data
Access trade history viagetTrades() and getTxOrders() to retrieve orders from specific settlement transactions.
Configuration Options
The constructor accepts:- Chain ID specification (required)
- Environment selection (prod/staging)
- Partner API key for higher rate limits
- Custom endpoints and rate limiting parameters
- Exponential backoff retry settings
Partner API (Authenticated Access)
Partners can use authenticated API access with higher rate limits via the Partner API gateway. Pass your API key when creating anOrderBookApi instance:
partners.cow.fi (prod) or partners.barn.cow.fi (staging) and includes the X-API-Key header. If you provide custom baseUrls, those take precedence over the default partner hosts, but the X-API-Key header is still sent with every request.
Additional Features
Price & Analytics
getNativePrice() retrieves token pricing, while getSolverCompetition() provides auction competition details.
App Data
Upload and retrieve metadata throughuploadAppData() and getAppData() methods.
Error Handling
ImplementsOrderBookApiError for API-specific exceptions with response status and messaging details.
Related Resources
- Quote Selection —
priceQualityoptions, timing strategies, and freshness best practices - How Intents Are Formed — fee pipeline breakdown (
feeAmount, amount stages, order construction) - Rate Limits & Quotas — per-endpoint limits, backoff strategies, and Cloudflare troubleshooting
- Creating Swap Orders — market order guide using the SDK
- Creating Limit Orders — limit order guide using the SDK