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) CoinDetail(ctx context.Context, id string) (Coin, error)
- func (c *Client) Coins(ctx context.Context, limit int) ([]CoinInfo, error)
- func (c *Client) Markets(ctx context.Context, currency string, limit, page int) ([]MarketCoin, error)
- func (c *Client) Price(ctx context.Context, ids []string, currencies ...string) ([]Price, error)
- func (c *Client) Trending(ctx context.Context) ([]TrendingCoin, error)
- type Coin
- type CoinInfo
- type Config
- type Domain
- type MarketCoin
- type Price
- 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) CoinDetail ¶ added in v0.1.3
CoinDetail returns the full detail object for a single coin.
func (*Client) Coins ¶ added in v0.1.4
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.
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) 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 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.