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
- type Client
- func (c *Client) CoinInfo(ctx context.Context, id string) (CoinDetail, error)
- func (c *Client) Markets(ctx context.Context, limit int) ([]Coin, error)
- func (c *Client) MarketsInCurrency(ctx context.Context, currency string, limit int) ([]Coin, 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 Coin
- type CoinDetail
- type CoinMarketData
- type Config
- type Domain
- type Price
- type SearchResult
- type TrendingCoin
Constants ¶
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 (*Client) CoinInfo ¶ added in v0.1.1
CoinInfo returns the full detail object for a single coin.
func (*Client) Markets ¶ added in v0.1.1
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
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
Price returns prices for the given coin IDs in the given currencies.
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) 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 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.