DexPaprika Go SDK
The official Go client library for the DexPaprika API, providing easy access to decentralized exchange data across multiple blockchain networks
Installation
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
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
client.Networks.List(ctx)
Endpoint: GET /networks
Gets all supported blockchain networks including Ethereum, Solana, etc.
Parameters:
ctx
* - Context for API request
Returns: Network IDs, names, and related information. Response Structure.
networks, err := client.Networks.List(ctx)
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
Returns: DEX IDs, names, pool counts, and volume information. Response Structure.
options := &dexpaprika.ListOptions{
Page: 0,
Limit: 10,
}
dexes, err := client.Networks.ListDexes(ctx, "ethereum", options)
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.)
Returns: Paginated list of pool objects with pricing data. Response Structure.
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
Returns: Paginated list of pools for the given network. Response Structure.
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
Returns: Paginated list of pools for the specified DEX. Response Structure.
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)
Returns: Detailed pool information including tokens, volumes, liquidity, and more. Response Structure.
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
Returns: List of transactions with details about tokens, amounts, and timestamps. Response Structure.
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)
Returns: Array of OHLCV data points for the specified time range and interval. Response Structure.
// 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)
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
Returns: Token details including price, market cap, volume, and metadata. Response Structure.
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
Returns: List of pools where the queried token is found. Response Structure.
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
)
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
Returns: Matching entities from all categories (tokens, pools, DEXes). Response Structure.
results, err := client.Search.Search(ctx, "ethereum")
client.Utils.GetStats(ctx)
Endpoint: GET /stats
Gets platform-wide statistics.
Parameters:
ctx
* - Context for API request
Returns: Counts of chains, DEXes, pools, and tokens indexed. Response Structure.
stats, err := client.Utils.GetStats(ctx)
Complete Example
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
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
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
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
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.
Was this page helpful?