Overview
The CoW Protocol Subgraph indexes on-chain trading data, making it easy to query historical trades, volume statistics, and protocol metrics. The SDK provides a type-safeSubgraphClient with built-in queries and support for custom GraphQL queries.
Setting Up the Subgraph Client
Supported Networks
The Subgraph is available on:- Ethereum Mainnet -
Chain.MAINNET - Gnosis Chain -
Chain.GNOSIS - Arbitrum One -
Chain.ARBITRUM_ONE - Base -
Chain.BASE - Sepolia Testnet -
Chain.SEPOLIA
Built-in Queries
The SDK includes pre-built queries for common use cases:Total Protocol Statistics
Daily Volume Statistics
Hourly Volume Statistics
Custom GraphQL Queries
You can execute custom GraphQL queries using theexecute() method:
Basic Custom Query
Query Orders with Filters
Query Trades
Advanced Query Examples
Token Trading Statistics
User Trading Activity
Trading Pairs Analysis
Working with Context Manager
Error Handling
Complete Example: Trading Dashboard
dashboard.py
Available Schema Types
The Subgraph schema includes these main types:- User - Trader information and statistics
- Order - Order details and status
- Trade - Executed trade information
- Token - Token metadata and statistics
- Pair - Trading pair information
- Settlement - Settlement transaction details
- DailyTotal - Daily aggregated statistics
- HourlyTotal - Hourly aggregated statistics
- Total - Overall protocol statistics
Query Optimization Tips
- Use pagination: Limit results with
firstandskipparameters - Filter early: Apply
whereclauses to reduce data transfer - Select specific fields: Only query fields you need
- Use orderBy: Sort results at the subgraph level
- Cache results: Store frequently accessed data locally
Next Steps
- Learn about Managing Orders to create and track orders
- Explore Swapping Tokens for executing trades
- Check App Data for order metadata
