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
- type Client
- func (c *Client) Coin(ctx context.Context, id string) (CoinDetail, error)
- func (c *Client) Markets(ctx context.Context, ids string, currency string, limit int) ([]CoinMarket, error)
- func (c *Client) Price(ctx context.Context, ids string, currencies string) ([]Price, error)
- func (c *Client) Search(ctx context.Context, query string) ([]SearchResult, error)
- func (c *Client) Trending(ctx context.Context) ([]TrendingCoin, error)
- type CoinDetail
- type CoinMarket
- type Config
- type Domain
- type Price
- type SearchResult
- type TrendingCoin
Constants ¶
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 (*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
Price returns prices for the given coin IDs in the given currencies. Each coin ID in the response becomes one Price struct.
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 ¶
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.
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.