Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) CoinDetail(ctx context.Context, id string) (*CoinDetail, error)
- func (c *Client) CoinHistory(ctx context.Context, id, date string) (*HistoricalData, error)
- func (c *Client) CoinMarketChart(ctx context.Context, id, vsCurrency, days, interval string) (*MarketChartResponse, error)
- func (c *Client) CoinMarketChartRange(ctx context.Context, id, vsCurrency string, from, to int64, interval string) (*MarketChartResponse, error)
- func (c *Client) CoinMarkets(ctx context.Context, vsCurrency string, perPage, page int, ...) ([]MarketCoin, error)
- func (c *Client) CoinOHLC(ctx context.Context, id, vsCurrency, days, interval string) (OHLCData, error)
- func (c *Client) CoinOHLCRange(ctx context.Context, id, vsCurrency string, from, to int64, interval string) (OHLCData, error)
- func (c *Client) Search(ctx context.Context, query string) (*SearchResponse, error)
- func (c *Client) SearchTrending(ctx context.Context, showMax string) (*TrendingResponse, error)
- func (c *Client) SetBaseURL(url string)
- func (c *Client) SimplePrice(ctx context.Context, ids []string, vsCurrency string) (PriceResponse, error)
- func (c *Client) TopGainersLosers(ctx context.Context, vsCurrency, duration, topCoins, priceChangePct string) (*GainersLosersResponse, error)
- type CoinDetail
- type CoinDetailMarket
- type GainerCoin
- type GainersLosersResponse
- type HistoricalData
- type HistoricalMarket
- type MarketChartResponse
- type MarketCoin
- type OHLCData
- type PriceResponse
- type RateLimitError
- type SearchCoin
- type SearchResponse
- type TrendingCategory
- type TrendingCoin
- type TrendingCoinData
- type TrendingCoinWrapper
- type TrendingNFT
- type TrendingResponse
Constants ¶
This section is empty.
Variables ¶
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 NewClientWithHTTP ¶
func (*Client) CoinDetail ¶
CoinDetail fetches detailed coin data (used in TUI detail view). https://docs.coingecko.com/v3.0.1/reference/coins-id
func (*Client) CoinHistory ¶
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 ¶
Search queries the CoinGecko search endpoint. https://docs.coingecko.com/v3.0.1/reference/search-data
func (*Client) SearchTrending ¶
SearchTrending fetches trending coins, NFTs, and categories. https://docs.coingecko.com/v3.0.1/reference/trending-search
func (*Client) SetBaseURL ¶
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 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 MarketChartResponse ¶
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 ¶
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 SearchResponse ¶
type SearchResponse struct {
Coins []SearchCoin `json:"coins"`
}
type TrendingCategory ¶
type TrendingCoin ¶
type TrendingCoinData ¶ added in v1.0.2
type TrendingCoinWrapper ¶
type TrendingCoinWrapper struct {
Item TrendingCoin `json:"item"`
}
type TrendingNFT ¶
type TrendingResponse ¶
type TrendingResponse struct {
Coins []TrendingCoinWrapper `json:"coins"`
NFTs []TrendingNFT `json:"nfts"`
Categories []TrendingCategory `json:"categories"`
}