api

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIKey  = fmt.Errorf("invalid API key — check your key with `cg status` or set a new one with `cg auth`")
	ErrPlanRestricted = fmt.Errorf("this endpoint requires a paid plan — upgrade at https://www.coingecko.com/en/api/pricing")
	ErrRateLimited    = fmt.Errorf("rate limited — please wait and try again")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(cfg *config.Config) *Client

func NewClientWithHTTP

func NewClientWithHTTP(cfg *config.Config, httpClient *http.Client) *Client

func (*Client) CoinDetail

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

CoinDetail fetches detailed coin data (used in TUI detail view). https://docs.coingecko.com/v3.0.1/reference/coins-id

func (*Client) CoinHistory

func (c *Client) CoinHistory(ctx context.Context, id, date string) (*HistoricalData, error)

CoinHistory fetches historical data for a coin on a specific date (DD-MM-YYYY). https://docs.coingecko.com/v3.0.1/reference/coins-id-history

func (*Client) CoinMarketChart added in v1.0.2

func (c *Client) CoinMarketChart(ctx context.Context, id, vsCurrency, days, interval string) (*MarketChartResponse, error)

CoinMarketChart fetches price/market data for the last N days. Paid plans support interval param: 5m (Enterprise), hourly, daily. https://docs.coingecko.com/reference/coins-id-market-chart

func (*Client) CoinMarketChartRange

func (c *Client) CoinMarketChartRange(ctx context.Context, id, vsCurrency string, from, to int64, interval string) (*MarketChartResponse, error)

CoinMarketChartRange fetches price data for a date range (UNIX timestamps in seconds). Paid plans support interval param: 5m (Enterprise), hourly, daily. https://docs.coingecko.com/reference/coins-id-market-chart-range

func (*Client) CoinMarkets

func (c *Client) CoinMarkets(ctx context.Context, vsCurrency string, perPage, page int, order, category string) ([]MarketCoin, error)

CoinMarkets fetches a paginated list of coins with market data. https://docs.coingecko.com/v3.0.1/reference/coins-markets

func (*Client) CoinOHLC

func (c *Client) CoinOHLC(ctx context.Context, id, vsCurrency, days, interval string) (OHLCData, error)

CoinOHLC fetches OHLC data for the last N days. Valid days: 1, 7, 14, 30, 90, 180, 365, max (paid). Paid plans support interval param: daily, hourly. https://docs.coingecko.com/reference/coins-id-ohlc

func (*Client) CoinOHLCRange added in v1.0.2

func (c *Client) CoinOHLCRange(ctx context.Context, id, vsCurrency string, from, to int64, interval string) (OHLCData, error)

CoinOHLCRange fetches OHLC data for a date range (UNIX timestamps in seconds, paid plans only). https://docs.coingecko.com/reference/coins-id-ohlc-range

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (*SearchResponse, error)

Search queries the CoinGecko search endpoint. https://docs.coingecko.com/v3.0.1/reference/search-data

func (*Client) SearchTrending

func (c *Client) SearchTrending(ctx context.Context, showMax string) (*TrendingResponse, error)

SearchTrending fetches trending coins, NFTs, and categories. https://docs.coingecko.com/v3.0.1/reference/trending-search

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string)

func (*Client) SimplePrice

func (c *Client) SimplePrice(ctx context.Context, ids []string, vsCurrency string) (PriceResponse, error)

SimplePrice fetches current prices for the given coin IDs. https://docs.coingecko.com/v3.0.1/reference/simple-price

func (*Client) TopGainersLosers

func (c *Client) TopGainersLosers(ctx context.Context, vsCurrency, duration, topCoins, priceChangePct string) (*GainersLosersResponse, error)

TopGainersLosers fetches top gaining and losing coins (paid plans only). https://docs.coingecko.com/reference/coins-top-gainers-losers

type CoinDetail

type CoinDetail struct {
	ID            string `json:"id"`
	Symbol        string `json:"symbol"`
	Name          string `json:"name"`
	MarketCapRank int    `json:"market_cap_rank"`
	Description   struct {
		EN string `json:"en"`
	} `json:"description"`
	MarketData *CoinDetailMarket `json:"market_data"`
}

type CoinDetailMarket

type CoinDetailMarket struct {
	CurrentPrice             map[string]float64 `json:"current_price"`
	MarketCap                map[string]float64 `json:"market_cap"`
	TotalVolume              map[string]float64 `json:"total_volume"`
	High24h                  map[string]float64 `json:"high_24h"`
	Low24h                   map[string]float64 `json:"low_24h"`
	PriceChangePercentage24h float64            `json:"price_change_percentage_24h"`
	ATH                      map[string]float64 `json:"ath"`
	ATHChangePercentage      map[string]float64 `json:"ath_change_percentage"`
	ATL                      map[string]float64 `json:"atl"`
	ATLChangePercentage      map[string]float64 `json:"atl_change_percentage"`
	CirculatingSupply        float64            `json:"circulating_supply"`
	TotalSupply              float64            `json:"total_supply"`
}

type GainerCoin

type GainerCoin struct {
	ID            string                 `json:"id"`
	Symbol        string                 `json:"symbol"`
	Name          string                 `json:"name"`
	Image         string                 `json:"image"`
	MarketCapRank int                    `json:"market_cap_rank"`
	Extra         map[string]interface{} `json:"-"`
}

GainerCoin uses dynamic JSON keys for price fields based on the vs_currency parameter. The API returns {currency} and {currency}_24h_change as keys (e.g. "usd", "usd_24h_change" or "eur", "eur_24h_change").

func (GainerCoin) MarshalJSON

func (g GainerCoin) MarshalJSON() ([]byte, error)

func (*GainerCoin) Price

func (g *GainerCoin) Price(vs string) float64

Price returns the price in the given vs currency.

func (*GainerCoin) PriceChange

func (g *GainerCoin) PriceChange(vs string) float64

PriceChange returns the 24h price change percentage in the given vs currency.

func (*GainerCoin) UnmarshalJSON

func (g *GainerCoin) UnmarshalJSON(data []byte) error

type GainersLosersResponse

type GainersLosersResponse struct {
	TopGainers []GainerCoin `json:"top_gainers"`
	TopLosers  []GainerCoin `json:"top_losers"`
}

type HistoricalData

type HistoricalData struct {
	ID         string            `json:"id"`
	Symbol     string            `json:"symbol"`
	Name       string            `json:"name"`
	MarketData *HistoricalMarket `json:"market_data"`
}

type HistoricalMarket

type HistoricalMarket struct {
	CurrentPrice map[string]float64 `json:"current_price"`
	MarketCap    map[string]float64 `json:"market_cap"`
	TotalVolume  map[string]float64 `json:"total_volume"`
}

type MarketChartResponse

type MarketChartResponse struct {
	Prices       [][]float64 `json:"prices"`
	MarketCaps   [][]float64 `json:"market_caps"`
	TotalVolumes [][]float64 `json:"total_volumes"`
}

type MarketCoin

type MarketCoin struct {
	ID                       string  `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"`
	TotalVolume              float64 `json:"total_volume"`
	PriceChangePercentage24h float64 `json:"price_change_percentage_24h"`
	High24h                  float64 `json:"high_24h"`
	Low24h                   float64 `json:"low_24h"`
	ATH                      float64 `json:"ath"`
	ATHChangePercentage      float64 `json:"ath_change_percentage"`
	ATL                      float64 `json:"atl"`
	ATLChangePercentage      float64 `json:"atl_change_percentage"`
	CirculatingSupply        float64 `json:"circulating_supply"`
	TotalSupply              float64 `json:"total_supply"`
}

type OHLCData

type OHLCData [][]float64

OHLC data: each entry is [timestamp, open, high, low, close]

type PriceResponse

type PriceResponse map[string]map[string]float64

Simple price response: map[coinID]map[field]value Fields include currency price (float64) and 24h change (float64).

type RateLimitError

type RateLimitError struct {
	RetryAfter int // seconds; 0 if Retry-After header was absent
}

RateLimitError carries the Retry-After metadata from a 429 response.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) Is

func (e *RateLimitError) Is(target error) bool

type SearchCoin

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

type SearchResponse

type SearchResponse struct {
	Coins []SearchCoin `json:"coins"`
}

type TrendingCategory

type TrendingCategory struct {
	ID                int     `json:"id"`
	Name              string  `json:"name"`
	MarketCap1hChange float64 `json:"market_cap_1h_change"`
}

type TrendingCoin

type TrendingCoin struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Symbol        string            `json:"symbol"`
	MarketCapRank int               `json:"market_cap_rank"`
	Score         int               `json:"score"`
	Data          *TrendingCoinData `json:"data"`
}

type TrendingCoinData added in v1.0.2

type TrendingCoinData struct {
	Price                    float64            `json:"price"`
	PriceChangePercentage24h map[string]float64 `json:"price_change_percentage_24h"`
}

type TrendingCoinWrapper

type TrendingCoinWrapper struct {
	Item TrendingCoin `json:"item"`
}

type TrendingNFT

type TrendingNFT struct {
	ID                   string  `json:"id"`
	Name                 string  `json:"name"`
	Symbol               string  `json:"symbol"`
	FloorPriceInUSD24hPC float64 `json:"floor_price_24h_percentage_change"`
}

type TrendingResponse

type TrendingResponse struct {
	Coins      []TrendingCoinWrapper `json:"coins"`
	NFTs       []TrendingNFT         `json:"nfts"`
	Categories []TrendingCategory    `json:"categories"`
}

Jump to

Keyboard shortcuts

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