API Integration
The CoW Protocol API provides direct access to the protocol's functionality through RESTful endpoints. This approach offers maximum flexibility and control for backend integrations and custom implementations.
Overview
The API integration allows you to interact with CoW Protocol at the lowest level, giving you complete control over order management, quote fetching, and trade execution. This is ideal for advanced integrations, backend services, and custom trading logic.
Key APIs
Order Book API
The primary API for creating and managing orders on CoW Protocol.
- Base URL:
https://api.cow.fi/ - Purpose: Quote generation, order submission, order management
- Authentication: No API key required for basic operations
Key Endpoints
POST /api/v1/quote- Get trading quotesPOST /api/v1/orders- Submit signed ordersGET /api/v1/orders/{uid}- Get order detailsDELETE /api/v1/orders/{uid}- Cancel ordersGET /api/v1/trades- Get trade history
Quick Start Example
1. Get a Quote
curl -X POST "https://api.cow.fi/mainnet/api/v1/quote" \
-H "Content-Type: application/json" \
-d '{
"sellToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"buyToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"sellAmountBeforeFee": "1000000000",
"kind": "sell",
"from": "0xYourWalletAddress"
}'
2. Apply Slippage and Sign Order
Before signing, you must apply slippage tolerance to protect against price movements. See the Quote to Order Tutorial for detailed examples.
import { domain, signOrder, OrderKind, OrderBalance, SigningScheme } from '@cowprotocol/contracts'
// Apply slippage to the quote before signing
// For sell orders: reduce buyAmount by slippage (e.g., 0.5%)
const buyAmountWithSlippage = BigInt(quoteResponse.quote.buyAmount) * 995n / 1000n
// Build order object for signing (uses enums, not strings)
const order = {
...quoteResponse.quote,
buyAmount: buyAmountWithSlippage.toString(),
receiver: walletAddress,
kind: OrderKind.SELL,
sellTokenBalance: OrderBalance.ERC20,
buyTokenBalance: OrderBalance.ERC20,
}
// Sign using @cowprotocol/contracts
const orderDomain = domain(1, '0x9008D19f58AAbD9eD0D60971565AA8510560ab41')
const signature = await signOrder(orderDomain, order, signer, SigningScheme.EIP712)
// Submit - API expects strings for kind/balance fields
const response = await fetch('https://api.cow.fi/mainnet/api/v1/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
...quoteResponse.quote,
buyAmount: buyAmountWithSlippage.toString(),
receiver: walletAddress,
signature: signature.data,
signingScheme: 'eip712',
from: walletAddress
})
})
const orderId = await response.text()
3. Monitor Order Status
// Check order status
const orderResponse = await fetch(
`https://api.cow.fi/mainnet/api/v1/orders/${orderId}`
)
const orderDetails = await orderResponse.json()
console.log('Order status:', orderDetails.status)
Network Endpoints
CoW Protocol APIs are available on multiple networks:
- Mainnet:
https://api.cow.fi/mainnet/api/v1/ - Gnosis Chain:
https://api.cow.fi/xdai/api/v1/ - Arbitrum:
https://api.cow.fi/arbitrum_one/api/v1/ - Base:
https://api.cow.fi/base/api/v1/ - Sepolia (Testnet):
https://api.cow.fi/sepolia/api/v1/
Order Signing
Orders must be cryptographically signed before submission. The signing process involves:
- EIP-712 Domain: Chain-specific domain separator
- Order Struct: Structured order data
- Signature: ECDSA signature or pre-signed order
import { ethers } from 'ethers'
// Example order signing with ethers.js
const domain = {
name: 'Gnosis Protocol',
version: 'v2',
chainId: 1,
verifyingContract: '0x9008D19f58AAbD9eD0D60971565AA8510560ab41'
}
const types = {
Order: [
{ name: 'sellToken', type: 'address' },
{ name: 'buyToken', type: 'address' },
{ name: 'receiver', type: 'address' },
// ... other order fields
]
}
const signature = await signer._signTypedData(domain, types, orderData)
Error Handling
The API returns standard HTTP status codes:
- 200: Success
- 400: Bad Request (invalid parameters)
- 404: Order not found
- 429: Rate limited
- 500: Internal server error
try {
const response = await fetch(apiUrl, requestOptions)
if (!response.ok) {
const error = await response.json()
throw new Error(`API Error: ${error.description}`)
}
return await response.json()
} catch (error) {
console.error('Order submission failed:', error)
}
When to Use the API
- Backend integration: Server-side order management
- Custom trading logic: Advanced order types and strategies
- High-frequency trading: Programmatic order placement
- Multi-chain applications: Cross-chain arbitrage and liquidity
- Analytics platforms: Order and trade data analysis
Rate Limits
- Quote requests: 10 requests/second
- Order submission: 5 requests/second
- General endpoints: 100 requests/minute
Next Steps
For complete API documentation including all endpoints, parameters, and response schemas, see:
- Quote to Order Tutorial - Step-by-step guide with slippage handling
- Order Book API Reference - Complete endpoint documentation
- API Documentation - Interactive API explorer
Resources
- Quote to Order Tutorial - Complete guide with slippage handling
- Order Book API Reference - Detailed API documentation
- API Explorer - Interactive documentation
- GitHub Examples - Code examples
- Order Signing Guide - Cryptographic signing details