CoinPaprika Go SDK

The official Go client library for the CoinPaprika API provides convenient access to cryptocurrency market data, including coin prices, volumes, market caps, and more.

Installation

Install the CoinPaprika Go SDK using go get:
go get github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika

Quick Start

Basic Usage

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    // Initialize the client
    client := coinpaprika.NewClient(nil)

    // Get all tickers
    tickers, err := client.Tickers.List(nil)
    if err != nil {
        log.Fatal(err)
    }

    // Display first 3 coins
    for idx, ticker := range tickers {
        if ticker.Name == nil || ticker.Symbol == nil || ticker.Rank == nil {
            continue
        }

        fmt.Println("Name:", *ticker.Name)
        fmt.Println("Symbol:", *ticker.Symbol)
        fmt.Println("Rank:", *ticker.Rank)
        
        if quoteUSD, ok := ticker.Quotes["USD"]; ok && quoteUSD.Price != nil {
            fmt.Printf("Price: %.2f USD\n\n", *quoteUSD.Price)
        }

        if idx >= 2 {
            break
        }
    }
}

Using Custom HTTP Client

package main

import (
    "fmt"
    "net/http"
    "time"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    // Create custom HTTP client with timeout
    customClient := &http.Client{
        Timeout: 10 * time.Second,
    }

    // Initialize CoinPaprika client with custom HTTP client
    client := coinpaprika.NewClient(customClient)

    // Get global market data
    global, err := client.Global.Get()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Total market cap: $%.0f\n", *global.MarketCapUSD)
    fmt.Printf("24h volume: $%.0f\n", *global.Volume24hUSD)
}

Pro API with API Key

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    // Initialize client with API key for Pro features
    client := coinpaprika.NewClient(nil, coinpaprika.WithAPIKey("YOUR_API_KEY"))

    // Get tickers with Pro features
    tickers, err := client.Tickers.List(nil)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Retrieved %d tickers\n", len(tickers))
}
Get your API key at coinpaprika.com/api

Common Use Cases

Getting Market Data

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil)

    // Get global market overview
    global, err := client.Global.Get()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Global Market Data:")
    if global.MarketCapUSD != nil {
        fmt.Printf("- Market Cap: $%.0f\n", *global.MarketCapUSD)
    }
    if global.Volume24hUSD != nil {
        fmt.Printf("- 24h Volume: $%.0f\n", *global.Volume24hUSD)
    }
    if global.CryptocurrenciesNumber != nil {
        fmt.Printf("- Active Cryptocurrencies: %d\n", *global.CryptocurrenciesNumber)
    }

    // Get top 10 tickers
    tickers, err := client.Tickers.List(nil)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("\nTop 10 Cryptocurrencies:")
    for i, ticker := range tickers {
        if i >= 10 {
            break
        }

        if ticker.Name == nil || ticker.Symbol == nil || ticker.Rank == nil {
            continue
        }

        var price float64
        var change float64
        if ticker.Quotes != nil && ticker.Quotes["USD"] != nil {
            if ticker.Quotes["USD"].Price != nil {
                price = *ticker.Quotes["USD"].Price
            }
            if ticker.Quotes["USD"].PercentChange24h != nil {
                change = *ticker.Quotes["USD"].PercentChange24h
            }
        }

        fmt.Printf("%d. %s (%s): $%.2f (%.2f%%)\n", 
            *ticker.Rank, *ticker.Name, *ticker.Symbol, price, change)
    }
}

Coin Information

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil)

    // Get specific coin data
    bitcoin, err := client.Coins.GetByID("btc-bitcoin")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Bitcoin Information:")
    if bitcoin.Name != nil {
        fmt.Printf("- Name: %s\n", *bitcoin.Name)
    }
    if bitcoin.Symbol != nil {
        fmt.Printf("- Symbol: %s\n", *bitcoin.Symbol)
    }
    if bitcoin.Rank != nil {
        fmt.Printf("- Rank: %d\n", *bitcoin.Rank)
    }

    // Get Bitcoin markets
    markets, err := client.Coins.GetMarketsByCoinID("btc-bitcoin")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Trading on %d markets\n", len(markets))
}

Historical Data

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil, coinpaprika.WithAPIKey("YOUR_API_KEY"))

    // Get historical OHLCV data (Pro feature)
    endTime := time.Now()
    startTime := endTime.AddDate(0, 0, -7) // Last 7 days

    ohlcv, err := client.Coins.GetHistoricalOHLCVByCoinID("btc-bitcoin", &coinpaprika.HistoricalOHLCVOptions{
        Quote: "usd",
        Start: startTime,
        End:   endTime,
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Retrieved %d OHLCV data points for Bitcoin\n", len(ohlcv))
    for _, data := range ohlcv[:3] { // Show first 3 days
        fmt.Printf("Date: %s, Open: $%.2f, High: $%.2f, Low: $%.2f, Close: $%.2f\n",
            data.TimeOpen.Format("2006-01-02"),
            data.Open, data.High, data.Low, data.Close)
    }
}

Search and Price Converter

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil)

    // Search for cryptocurrencies
    searchResults, err := client.Search.Search(&coinpaprika.SearchOptions{
        Query:      "bitcoin",
        Categories: "currencies",
        Limit:      5,
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Found %d coins matching 'bitcoin'\n", len(searchResults.Currencies))
    for _, coin := range searchResults.Currencies {
        fmt.Printf("- %s (%s)\n", coin.Name, coin.Symbol)
    }

    // Price converter
    conversion, err := client.PriceConverter.PriceConverter(&coinpaprika.PriceConverterOptions{
        BaseCurrencyID:  "btc-bitcoin",
        QuoteCurrencyID: "eth-ethereum",
        Amount:          1,
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("1 BTC = %.6f ETH\n", conversion.Price)
}

Error Handling

package main

import (
    "fmt"
    "log"

    "github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil)

    // Handle errors gracefully
    coin, err := client.Coins.GetByID("invalid-coin-id")
    if err != nil {
        // The client returns a standard error, which may include the HTTP status code from the API.
        log.Printf("An error occurred: %v", err)
        return
    }

    fmt.Printf("Coin: %s\n", *coin.Name)
}

Advanced Usage

Rate Limiting

The client does not automatically handle rate limiting. If you exceed the request limit for your plan, the API will return an error with an HTTP 429 “Too Many Requests” status code. Your application should handle these errors, for example by implementing a backoff-and-retry mechanism.

Custom Request Options

package main

import (
	"log"

	"github.com/coinpaprika/coinpaprika-api-go-client/v2/coinpaprika"
)

func main() {
    client := coinpaprika.NewClient(nil)

    // Get tickers with custom options
    options := &coinpaprika.TickersOptions{
        Quotes: "USD,BTC",
    }

    tickers, err := client.Tickers.List(options)
    if err != nil {
        panic(err)
    }

    // Process tickers...
	log.Printf("Fetched %d tickers", len(tickers))
}

Available Methods

The Go SDK is organized into services that correspond to the API endpoints.

Global

Coins

People

Tags

Tickers

Exchanges

Tools

Examples Repository

Check out practical examples in the official repository.

Requirements

  • Go 1.13 or higher
  • Internet connection for API calls

License

This library is available under the MIT license. See the LICENSE file for more info.