coingecko

package
v0.1.2 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.

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 = "api.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) Coin added in v0.1.2

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

Coin returns the full detail object for a single coin.

func (*Client) Markets added in v0.1.1

func (c *Client) Markets(ctx context.Context, ids string, currency string, limit int) ([]CoinMarket, error)

Markets returns coins sorted by market cap descending, optionally filtered by a comma-separated list of IDs. Pass limit <= 0 for API default (100).

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. Each coin ID in the response becomes one Price struct.

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 CoinDetail added in v0.1.1

type CoinDetail struct {
	ID           string  `kit:"id" json:"id"`
	Symbol       string  `json:"symbol"`
	Name         string  `json:"name"`
	Description  string  `json:"description"`
	GenesisDate  string  `json:"genesis_date"`
	CurrentUSD   float64 `json:"current_price_usd"`
	MarketCapUSD float64 `json:"market_cap_usd"`
	ATH_USD      float64 `json:"ath_usd"`
	Change24h    float64 `json:"price_change_24h_pct"`
}

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

type CoinMarket added in v0.1.2

type CoinMarket struct {
	ID                string  `kit:"id" json:"id"`
	Symbol            string  `json:"symbol"`
	Name              string  `json:"name"`
	CurrentPrice      float64 `json:"current_price"`
	MarketCap         float64 `json:"market_cap"`
	MarketCapRank     int     `json:"market_cap_rank"`
	PriceChange24h    float64 `json:"price_change_24h_pct"`
	TotalVolume       float64 `json:"total_volume"`
	CirculatingSupply float64 `json:"circulating_supply"`
	ATH               float64 `json:"ath"`
}

CoinMarket is one entry from the /coins/markets listing.

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). - known coin name/symbol (e.g. "bitcoin", "btc") → ("coin", input) - "," in string → ("ids", input) - otherwise → ("query", input)

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 struct {
	CoinID string             `kit:"id" json:"coin_id"`
	Prices map[string]float64 `json:"prices"`
}

Price is a coin's price in one or more currencies.

type SearchResult added in v0.1.1

type SearchResult struct {
	ID            string `kit:"id" json:"id"`
	Name          string `json:"name"`
	Symbol        string `json:"symbol"`
	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 {
	ID            string  `kit:"id" json:"id"`
	Symbol        string  `json:"symbol"`
	Name          string  `json:"name"`
	MarketCapRank int     `json:"market_cap_rank"`
	PriceBTC      float64 `json:"price_btc"`
}

TrendingCoin is one entry from the /search/trending response.

Jump to

Keyboard shortcuts

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