The official Go client library for the DexPaprika API, providing easy access to decentralized exchange data across multiple blockchain networks
go get github.com/coinpaprika/dexpaprika-sdk-go
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
}
Show methods
/networks
Gets all supported blockchain networks including Ethereum, Solana, etc.Parameters:ctx
* - Context for API requestnetworks, err := client.Networks.List(ctx)
Show methods
/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 pageoptions := &dexpaprika.ListOptions{
Page: 0,
Limit: 10,
}
dexes, err := client.Networks.ListDexes(ctx, "ethereum", options)
Show methods
/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.)options := &dexpaprika.ListOptions{
Limit: 10,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.List(ctx, options)
/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 parametersoptions := &dexpaprika.ListOptions{
Limit: 5,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.ListByNetwork(ctx, "ethereum", options)
/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 parametersoptions := &dexpaprika.ListOptions{
Limit: 10,
OrderBy: "volume_usd",
Sort: "desc",
}
pools, err := client.Pools.ListByDex(ctx, "ethereum", "uniswap_v2", options)
/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)options := &dexpaprika.PoolDetailOptions{
Inversed: false,
}
poolDetails, err := client.Pools.GetDetails(ctx, "ethereum", "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", options)
/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 parametersoptions := &dexpaprika.ListOptions{
Limit: 20,
Page: 0,
}
transactions, err := client.Pools.GetTransactions(ctx, "ethereum", "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc", options)
/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)// 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
/networks/{network}/tokens/{token_address}
Gets comprehensive token information.Parameters:ctx
* - Context for API requestnetworkId
* - ID of the networktokenAddress
* - Token contract addresstoken, err := client.Tokens.GetDetails(ctx, "ethereum", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
/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 tokensoptions := &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
/search
Searches across tokens, pools, and DEXes using a query string.Parameters:ctx
* - Context for API requestquery
* - Search query stringresults, err := client.Search.Search(ctx, "ethereum")
Show methods
/stats
Gets platform-wide statistics.Parameters:ctx
* - Context for API requeststats, err := client.Utils.GetStats(ctx)
Show 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)
}
}
Show 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")
}
}
}
Show 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))
}
Show pagination
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)
}
Show 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
}
Was this page helpful?