coingecko

package
v0.1.4 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) CoinDetail added in v0.1.3

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

CoinDetail returns the full detail object for a single coin.

func (*Client) Coins added in v0.1.4

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

Coins returns the full list of coin IDs from CoinGecko. limit <= 0 means return all; otherwise return the first limit entries.

func (*Client) Markets added in v0.1.1

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

Markets returns coins sorted by market cap descending. Pass limit <= 0 for the default (25). page is 1-indexed.

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 one or more currencies. One Price is emitted per (coin ID, currency) pair.

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 {
	ID          string `json:"id"          kit:"id"`
	Symbol      string `json:"symbol"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Price       string `json:"price"`
	MarketCap   string `json:"market_cap"`
	Volume24h   string `json:"volume_24h"`
	High24h     string `json:"high_24h"`
	Low24h      string `json:"low_24h"`
}

Coin is the full coin detail from /coins/{id}.

type CoinInfo added in v0.1.4

type CoinInfo struct {
	ID     string `json:"id"     kit:"id"`
	Symbol string `json:"symbol"`
	Name   string `json:"name"`
}

CoinInfo is a minimal coin entry from the /coins/list endpoint.

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. It carries no state; the per-run client is built by the factory Register hands kit.

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 MarketCoin added in v0.1.4

type MarketCoin struct {
	ID             string  `json:"id"                       kit:"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"`
	TotalVolume    float64 `json:"total_volume"`
}

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

type Price added in v0.1.1

type Price struct {
	ID       string  `json:"id"       kit:"id"`
	Currency string  `json:"currency"`
	Price    float64 `json:"price"`
}

Price is a coin's current price in a single currency.

type TrendingCoin added in v0.1.1

type TrendingCoin struct {
	ID            string  `json:"id"              kit:"id"`
	Name          string  `json:"name"`
	Symbol        string  `json:"symbol"`
	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