See also: REST intro,
Networks,
Pools
Installation
Copy
go get github.com/coinpaprika/dexpaprika-sdk-go
Prerequisites
- Go 1.24 or higher
- Connection to the internet to access the DexPaprika API
- No API key required
Quick Example: Get Token Price
Copy
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func main() {
// Create client
client := dexpaprika.NewClient()
// Create context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Get WETH token details on Ethereum
token, err := client.Tokens.GetDetails(ctx, "ethereum", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
if err != nil {
log.Fatalf("Error getting token details: %v", err)
}
fmt.Printf("%s: $%.2f\n", token.Name, token.PriceUSD)
// Output: Wrapped Ether: $3245.67
}
API Methods Reference
Parameters marked with an asterisk (*) are required.
Show methods
Show methods
client.Networks.List(ctx)
Endpoint: GET/networks
Gets all supported blockchain networks including Ethereum, Solana, etc.Parameters:ctx
* - Context for API request
Copy
networks, err := client.Networks.List(ctx)
Show methods
Show methods
client.Networks.ListDexes(ctx, networkId, options)
Endpoint: GET/networks/{network}/dexes
Gets all DEXes on a specific network.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the network (e.g., ‘ethereum’, ‘solana’)options
- ListOptions containing pagination parameters:Page
- Page number for pagination (starts at 0)Limit
- Number of results per page
Copy
options := &dexpaprika.ListOptions{
Page: 0,
Limit: 10,
}
dexes, err := client.Networks.ListDexes(ctx, "ethereum", options)
Show methods
Show methods
client.Pools.List(ctx, options)
Endpoint: GET/pools
Gets top pools across all networks with pagination.Parameters:ctx
* - Context for API requestoptions
- ListOptions containing pagination and sorting parameters:Page
- Page number for pagination (starts at 0)Limit
- Number of results per pageSort
- Sort direction (‘asc’ or ‘desc’)OrderBy
- Field to sort by (‘volume_usd’, ‘liquidity_usd’, etc.)
Copy
options := &dexpaprika.ListOptions{
Limit: 10,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.List(ctx, options)
client.Pools.ListByNetwork(ctx, networkId, options)
Endpoint: GET/networks/{network}/pools
Gets pools on a specific network with pagination and sorting options.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networkoptions
- ListOptions containing pagination and sorting parameters
Copy
options := &dexpaprika.ListOptions{
Limit: 5,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.ListByNetwork(ctx, "ethereum", options)
client.Pools.ListByDex(ctx, networkId, dexId, options)
Endpoint: GET/networks/{network}/dexes/{dex}/pools
Gets pools on a specific DEX within a network with pagination.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networkdexId
* - ID of the DEXoptions
- ListOptions containing pagination and sorting parameters
Copy
options := &dexpaprika.ListOptions{
Limit: 10,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.ListByDex(ctx, "ethereum", "uniswap_v2", options)
client.Pools.GetDetails(ctx, networkId, poolAddress, options)
Endpoint: GET/networks/{network}/pools/{pool_address}
Gets detailed information about a specific pool.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networkpoolAddress
* - On-chain address of the pooloptions
- PoolDetailOptions containing:Inversed
- Whether to invert the price ratio (boolean)
Copy
options := &dexpaprika.PoolDetailOptions{
Inversed: false,
}
poolDetails, err := client.Pools.GetDetails(ctx, "ethereum", "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", options)
client.Pools.GetTransactions(ctx, networkId, poolAddress, options)
Endpoint: GET/networks/{network}/pools/{pool_address}/transactions
Gets transaction history for a specific pool with pagination.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networkpoolAddress
* - On-chain address of the pooloptions
- ListOptions containing pagination parameters
Copy
options := &dexpaprika.ListOptions{
Limit: 20,
Page: 0,
}
transactions, err := client.Pools.GetTransactions(ctx, "ethereum", "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", options)
client.Pools.GetOHLCV(ctx, networkId, poolAddress, options)
Endpoint: GET/networks/{network}/pools/{pool_address}/ohlcv
Gets OHLCV (Open, High, Low, Close, Volume) chart data for a pool.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networkpoolAddress
* - On-chain address of the pooloptions
- OHLCVOptions containing:Start
* - Start time (time.Time or string ISO format)End
- End time (optional)Limit
- Number of data points to returnInterval
- Time interval (‘1h’, ‘6h’, ‘24h’, etc.)Inversed
- Whether to invert the price ratio (boolean)
Copy
// Start time 7 days ago
startTime := time.Now().AddDate(0, 0, -7)
options := &dexpaprika.OHLCVOptions{
Start: startTime,
Limit: 100,
Interval: "1h",
Inversed: false,
}
ohlcv, err := client.Pools.GetOHLCV(ctx, "ethereum", "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", options)
Show methods
Show methods
client.Tokens.GetDetails(ctx, networkId, tokenAddress)
Endpoint: GET/networks/{network}/tokens/{token_address}
Gets comprehensive token information.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networktokenAddress
* - Token contract address
Copy
token, err := client.Tokens.GetDetails(ctx, "ethereum", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
client.Tokens.GetPools(ctx, networkId, tokenAddress, options, additionalTokenAddress)
Endpoint: GET/networks/{network}/tokens/{token_address}/pools
Gets pools containing a specific token.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networktokenAddress
* - Token contract addressoptions
- ListOptions containing pagination and sorting parametersadditionalTokenAddress
- Optional second token address to filter for pairs with both tokens
Copy
options := &dexpaprika.ListOptions{
Limit: 10,
Page: 0,
OrderBy: "volume_usd",
Sort: "desc",
}
// Get all WETH-USDC pools
pools, err := client.Tokens.GetPools(
ctx,
"ethereum",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
options,
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
)
Show methods
Show methods
client.Search.Search(ctx, query)
Endpoint: GET/search
Searches across tokens, pools, and DEXes using a query string.Parameters:ctx
* - Context for API requestquery
* - Search query string
Copy
results, err := client.Search.Search(ctx, "ethereum")
Show methods
Show methods
client.Utils.GetStats(ctx)
Endpoint: GET/stats
Gets platform-wide statistics.Parameters:ctx
* - Context for API request
Copy
stats, err := client.Utils.GetStats(ctx)
Complete Example
Show example
Show example
Copy
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func main() {
// Initialize client
client := dexpaprika.NewClient()
// Create context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Get Ethereum network details
networks, err := client.Networks.List(ctx)
if err != nil {
log.Fatalf("Error fetching networks: %v", err)
}
var ethereum *dexpaprika.Network
for _, network := range networks {
if network.ID == "ethereum" {
ethereum = &network
break
}
}
if ethereum == nil {
log.Fatal("Ethereum network not found")
}
fmt.Printf("Found %s with %d DEXes\n", ethereum.DisplayName, ethereum.DexesCount)
// Get WETH token details
weth, err := client.Tokens.GetDetails(
ctx,
"ethereum",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
)
if err != nil {
log.Fatalf("Error fetching token details: %v", err)
}
fmt.Printf("%s price: $%.2f\n", weth.Name, weth.PriceUSD)
// Find WETH/USDC pools
options := &dexpaprika.ListOptions{
Limit: 5,
Page: 0,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Tokens.GetPools(
ctx,
"ethereum",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
options,
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
)
if err != nil {
log.Fatalf("Error fetching pools: %v", err)
}
// Show top pools
fmt.Println("Top WETH/USDC pools:")
for _, pool := range pools.Pools {
fmt.Printf("%s: $%.2f 24h volume\n", pool.DexName, pool.VolumeUSD)
}
}
Advanced Features
Error Handling
Show error handling
Show error handling
Copy
import (
"context"
"errors"
"fmt"
"log"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func handleAPIErrors() {
client := dexpaprika.NewClient()
ctx := context.Background()
// Attempt to get a token with an invalid address
_, err := client.Tokens.GetDetails(ctx, "ethereum", "0xinvalidaddress")
if err != nil {
// Check for specific error types
var apiErr *dexpaprika.APIError
if errors.As(err, &apiErr) {
switch apiErr.StatusCode {
case 404:
fmt.Println("Token not found")
case 429:
fmt.Println("Rate limit exceeded, retry after a delay")
case 500:
fmt.Println("Server error, retry may succeed")
default:
fmt.Printf("API error: %s\n", apiErr.Message)
}
} else {
// Handle non-API errors (like network issues)
fmt.Printf("Non-API error: %v\n", err)
}
// Check if error is retryable
if dexpaprika.IsRetryable(err) {
fmt.Println("This error is retryable")
}
}
}
Caching
Show caching
Show caching
Copy
import (
"context"
"fmt"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func useCaching() {
// Create a regular client
client := dexpaprika.NewClient()
// Create a cached client with 5-minute TTL
cachedClient := dexpaprika.NewCachedClient(client, nil, 5*time.Minute)
// Create context
ctx := context.Background()
// First call - hits the API
startTime := time.Now()
networks, err := cachedClient.GetNetworks(ctx)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("First call (API): %d networks, took %v\n", len(networks), time.Since(startTime))
// Second call - served from cache (much faster)
startTime = time.Now()
networks, err = cachedClient.GetNetworks(ctx)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Second call (cached): %d networks, took %v\n", len(networks), time.Since(startTime))
}
Pagination Helpers
Show pagination
Show pagination
Copy
import (
"context"
"fmt"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func usePagination() {
client := dexpaprika.NewClient()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Create a paginator for Ethereum pools with 50 items per page
options := &dexpaprika.ListOptions{
Limit: 50,
OrderBy: "volume_usd",
Sort: "desc",
}
paginator := dexpaprika.NewPoolsPaginator(client, options).ForNetwork("ethereum")
// Count total pools processed
totalPools := 0
// Process first 3 pages (or fewer if there aren't that many)
for i := 0; i < 3 && paginator.HasNextPage(); i++ {
// Get next page of results
if err := paginator.GetNextPage(ctx); err != nil {
fmt.Printf("Error getting page: %v\n", err)
break
}
// Process current page
pools := paginator.GetCurrentPage()
totalPools += len(pools)
// Process first few pools in each page
fmt.Printf("=== Page %d ===\n", i+1)
for j, pool := range pools {
if j >= 3 {
fmt.Printf("...and %d more pools\n", len(pools)-3)
break
}
fmt.Printf("%s: $%.2f 24h volume\n", pool.DexName, pool.VolumeUSD)
}
}
fmt.Printf("Processed %d pools total\n", totalPools)
}
Custom Configuration
Show configuration
Show configuration
Copy
import (
"net/http"
"time"
"github.com/coinpaprika/dexpaprika-sdk-go/dexpaprika"
)
func configureClient() *dexpaprika.Client {
// Create a client with custom configuration
client := dexpaprika.NewClient(
// Custom HTTP client with longer timeout
dexpaprika.WithHTTPClient(&http.Client{
Timeout: 60 * time.Second,
}),
// Custom retry configuration (5 retries with backoff)
dexpaprika.WithRetryConfig(5, 2*time.Second, 30*time.Second),
// Rate limiting to 3 requests per second
dexpaprika.WithRateLimit(3.0),
// Custom user agent
dexpaprika.WithUserAgent("MyApp/1.0 DexPaprikaClient"),
)
return client
}
Resources
API Status
The DexPaprika API provides consistent data with stable endpoints. No API key is currently required to access the service. We aim to maintain backward compatibility and provide notice of any significant changes.FAQs
Do I need an API key with this SDK?
Do I need an API key with this SDK?
No. The API is public; no keys or registration required.
How do I find identifiers?
How do I find identifiers?
Use Coverage Checker or list Networks and query Tokens/Pools to discover addresses.
How do I get historical or transactions data?
How do I get historical or transactions data?
Use pools/transactions endpoints with
pool_address
, network
, and time/paging params as documented.What about rate limiting?
What about rate limiting?
Handle retries for transient HTTP errors and keep calls reasonable for public endpoints.