Creating Swap Orders
Swap orders are market orders that automatically fetch a quote and create an order in one step. The SDK handles all the complexity of parameters, calculations, and signing.Basic Flow
The basic trading flow consists of three steps:1
Get a quote (price) for a trade
The SDK fetches the current market price from the CoW Protocol API
2
Sign the order
Sign the order using EIP-712 signature
3
Post the order to the order-book
Submit the signed order to the CoW Protocol order book
Using postSwapOrder
ThepostSwapOrder method combines all three steps into one convenient function.
Required Parameters
kind- The order kind (OrderKind.SELLorOrderKind.BUY)sellToken- The sell token addresssellTokenDecimals- The sell token decimalsbuyToken- The buy token addressbuyTokenDecimals- The buy token decimalsamount- The amount to sell/buy in atoms (smallest unit)
Example
Optional Parameters
You can customize your swap order with these optional parameters:Example with Optional Parameters
Slippage is expressed in basis points (BPS). For example:
- 50 BPS = 0.5%
- 100 BPS = 1%
- 200 BPS = 2%
Advanced Settings
For more control over the order creation process, useSwapAdvancedSettings:
Quote Request Customization
Adding Hooks
You can add pre-hooks that execute before your order is settled:Two-Step Process: getQuote + postSwapOrderFromQuote
If you want to show the quote to users before creating an order, use the two-step approach:Quote Results
ThequoteResults object contains:
tradeParameters- Trade type, assets, amounts and optional parametersamountsAndCosts- Order sell/buy amounts including network costs, fees and slippageorderToSign- Order parameters ready for signingquoteResponse- Raw DTO from the Quote APIappDataInfo- Order’s metadataorderTypedData- EIP-712 typed data for signing
Order Kinds
The SDK supports two order kinds:- SELL Orders
- BUY Orders
Sell orders specify the exact amount you want to sell:You’ll receive at least the quoted buy amount (minus slippage).
Next Steps
- Learn about Token Approvals before trading
- Explore Limit Orders for price-specific trades
- See Order Management to track and cancel orders