Skip to main content

Programmatic Orders

The CoW Protocol Composable SDK enables sophisticated trading strategies through programmatic orders that execute automatically when specified conditions are met. The ComposableCoW contract implements these orders, allowing you to build advanced trading logic without constant monitoring.

Installation

Core Components

ConditionalOrderFactory

Registry-based factory for creating different types of programmatic orders:

Multiplexer

Manages batches of programmatic orders using merkle trees:

ConditionalOrder

Base class for implementing custom programmatic order types:

Basic Usage

Standalone Setup

With CoW SDK

Order Types

Stop-Loss Orders

Automatically sell when price drops below a threshold:

Limit Orders

Execute trades at specific price points:

DCA (Dollar Cost Averaging)

DCA strategies are implemented using TWAP orders. A TWAP order splits a total amount into equal parts executed at regular intervals — which is exactly what DCA does. For example, to DCA 3,000USDCintoETHover30days(3,000 USDC into ETH over 30 days (100/day):
Each part sells 100 USDC for WETH once per day. See the TWAP Orders guide for full configuration options including price protection.

Merkle Tree Management

Programmatic orders are stored in merkle trees for efficient on-chain verification:

Order Validation

Validate programmatic orders before execution:

Context Dependencies

Orders can depend on external data sources:

Order Registry Management

Register custom order types:

Smart Contract Integration

ComposableCoW Contract

Proof Generation and Storage

Complete Example

Here’s a complete example setting up a stop-loss order:

Best Practices

Always validate orders before submission

Use the isValid() method to catch configuration errors early:

Store proofs off-chain

Generate and store merkle proofs off-chain to enable watchtowers to execute your orders:

Use appropriate context factories

Set context factories for orders that need on-chain data:

Next Steps

  • TWAP Orders: Learn about Time-Weighted Average Price orders
  • Hooks: Execute custom logic with pre and post hooks
Last modified on March 12, 2026