Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions docs/cow-protocol/integrate/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The primary API for creating and managing orders on CoW Protocol.
- `POST /api/v1/orders` - Submit signed orders
- `GET /api/v1/orders/{uid}` - Get order details
- `DELETE /api/v1/orders/{uid}` - Cancel orders
- `GET /api/v1/trades` - Get trade history
- `GET /api/v2/trades` - Get trade history

## Quick Start Example

Expand All @@ -31,29 +31,48 @@ The primary API for creating and managing orders on CoW Protocol.
curl -X POST "https://api.cow.fi/mainnet/api/v1/quote" \
-H "Content-Type: application/json" \
-d '{
"sellToken": "0xA0b86a33E6411Ec5d0b9dd2E7dC15A9CAA6C1F8e",
"sellToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"buyToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"sellAmountBeforeFee": "1000000",
"sellAmountBeforeFee": "1000000000",
"kind": "sell",
"from": "0xYourWalletAddress"
}'
```

### 2. Sign and Submit Order
### 2. Apply Slippage and Sign Order

:::caution Important
Before signing, you should apply slippage tolerance to protect against price movements. See the [Quote to Order Tutorial](../tutorials/quote-to-order.mdx) for detailed examples.
:::

```javascript
// After getting a quote, sign the order
// 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
const sellAmount = BigInt(quoteResponse.quote.sellAmount) + BigInt(quoteResponse.quote.feeAmount)
const feeAmount = BigInt(0)

// Build order for signing
const order = {
...quoteResponse,
signature: await signOrder(quoteResponse, signer),
...quoteResponse.quote,
sellAmount: sellAmount.toString(),
buyAmount: buyAmountWithSlippage.toString(),
feeAmount: feeAmount.toString()
}

const signature = await signOrder(quoteResponse, signer)

const signedOrder = {
...order,
signature: signature,
signingScheme: "eip712"
}

// Submit the signed order
const response = await fetch('https://api.cow.fi/mainnet/api/v1/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(order)
body: JSON.stringify(signedOrder)
})

const orderId = await response.text()
Expand Down Expand Up @@ -163,4 +182,5 @@ For complete API documentation including all endpoints, parameters, and response
- **[Order Book API Reference](/cow-protocol/reference/apis/orderbook)** - Detailed API documentation
- **[API Explorer](https://api.cow.fi/docs/)** - Interactive documentation
- **[GitHub Examples](https://github.com/cowprotocol/cow-sdk/tree/main/examples)** - Code examples
- **[Order Signing Guide](../reference/core/signing_schemes.mdx)** - Cryptographic signing details
- **[Order Signing Guide](../reference/core/signing_schemes.mdx)** - Cryptographic signing details
- **[Quote to Order Tutorial](../tutorials/quote-to-order.mdx)** - Complete guide with slippage handling
Loading