coingecko

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package coingecko is the library behind the coingecko command line: the HTTP client, request shaping, and the typed data models for the CoinGecko public API (markets and trending).

The free CoinGecko API requires no key. The client paces requests at a 2-second floor to stay well within the ~30 req/min free-tier limit, and retries transient failures (429 and 5xx) with exponential backoff.

Index

Constants

View Source
const Host = "coingecko.com"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to CoinGecko over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) CoinInfo added in v0.1.1

func (c *Client) CoinInfo(ctx context.Context, id string) (CoinDetail, error)

CoinInfo returns the full detail object for a single coin.

func (*Client) Markets added in v0.1.1

func (c *Client) Markets(ctx context.Context, limit int) ([]Coin, error)

Markets returns the top n coins by market capitalisation descending. Pass limit <= 0 to use the default of 20.

func (*Client) MarketsInCurrency added in v0.1.1

func (c *Client) MarketsInCurrency(ctx context.Context, currency string, limit int) ([]Coin, error)

Markets returns the top n coins by market capitalisation in the given currency. If currency is empty, "usd" is used. Pass limit <= 0 to use the default of 20.

func (*Client) Price added in v0.1.1

func (c *Client) Price(ctx context.Context, ids []string, currencies []string) (Price, error)

Price returns prices for the given coin IDs in the given currencies.

func (*Client) Search added in v0.1.1

func (c *Client) Search(ctx context.Context, query string) ([]SearchResult, error)

Search searches for coins matching the given query string.

func (*Client) Trending added in v0.1.1

func (c *Client) Trending(ctx context.Context) ([]TrendingCoin, error)

Trending returns the currently trending coins (most searched in the last 24h).

type Coin added in v0.1.1

type Coin struct {
	Rank          int     `json:"rank"`
	ID            string  `json:"id"`
	Symbol        string  `json:"symbol"`
	Name          string  `json:"name"`
	PriceUSD      float64 `json:"price_usd"`
	Change24h     float64 `json:"change_24h"` // percentage
	MarketCapUSD  float64 `json:"market_cap_usd"`
	MarketCapRank int     `json:"market_cap_rank"`
	Volume24hUSD  float64 `json:"volume_24h_usd"`
	URL           string  `json:"url"` // https://www.coingecko.com/en/coins/{id}
}

Coin is one entry from the CoinGecko markets listing.

type CoinDetail added in v0.1.1

type CoinDetail struct {
	ID            string            `json:"id"`
	Symbol        string            `json:"symbol"`
	Name          string            `json:"name"`
	MarketCapRank int               `json:"market_cap_rank"`
	MarketData    CoinMarketData    `json:"market_data"`
	Description   map[string]string `json:"description"`
	Categories    []string          `json:"categories"`
}

CoinDetail is the full coin object returned by /coins/{id}.

type CoinMarketData added in v0.1.1

type CoinMarketData struct {
	CurrentPrice      map[string]float64 `json:"current_price"`
	MarketCap         map[string]float64 `json:"market_cap"`
	PriceChangePct24h float64            `json:"price_change_percentage_24h"`
}

CoinMarketData holds the market_data sub-object from /coins/{id}.

type Config added in v0.1.1

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the free tier.

type Domain

type Domain struct{}

Domain is the coingecko driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Price added in v0.1.1

type Price map[string]map[string]float64

Price maps coin ID -> currency -> price value.

type SearchResult added in v0.1.1

type SearchResult struct {
	ID            string `json:"id"`
	Symbol        string `json:"symbol"`
	Name          string `json:"name"`
	MarketCapRank int    `json:"market_cap_rank"`
}

SearchResult is one coin entry from the /search response.

type TrendingCoin added in v0.1.1

type TrendingCoin struct {
	Rank          int    `json:"rank"`
	ID            string `json:"id"`
	Symbol        string `json:"symbol"`
	Name          string `json:"name"`
	MarketCapRank int    `json:"market_cap_rank"`
	URL           string `json:"url"`
}

TrendingCoin is one entry from the CoinGecko trending search result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL