Documentation
ΒΆ
Overview ΒΆ
Package coingecko provides a comprehensive Go client for the CoinGecko API.
CoinGecko is a cryptocurrency data aggregation platform that provides real-time pricing, market data, historical charts, and more for thousands of cryptocurrencies.
Features ΒΆ
- Complete API coverage for all CoinGecko endpoints
- Support for both Free and Pro API tiers
- Type-safe API with strongly typed parameters
- Configurable HTTP client with custom options
- WebSocket support for real-time data
- Comprehensive error handling
Installation ΒΆ
go get github.com/tigusigalpa/coingecko-go
Quick Start ΒΆ
Basic usage with the free API:
package main
import (
"fmt"
"log"
coingecko "github.com/tigusigalpa/coingecko-go"
)
func main() {
cg := coingecko.New()
prices, err := cg.Simple().Price(
[]string{"bitcoin"},
[]string{"usd"},
nil,
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Bitcoin: $%.2f\n", prices["bitcoin"]["usd"])
}
Using Pro API ΒΆ
To use the Pro API with authentication:
cg := coingecko.New(
coingecko.WithAPIKey("your-api-key"),
coingecko.WithProAPI(true),
)
Custom HTTP Client ΒΆ
You can provide a custom HTTP client with specific settings:
import (
"net/http"
"time"
)
httpClient := &http.Client{
Timeout: 60 * time.Second,
}
cg := coingecko.New(
coingecko.WithHTTPClient(httpClient),
)
API Endpoints ΒΆ
The client provides access to all CoinGecko API endpoints organized into logical groups:
- Simple API: Quick price lookups and supported currencies
- Coins API: Comprehensive coin data, markets, and historical charts
- Contract API: Token data by contract address
- Asset Platforms API: Blockchain platforms and token lists
- Categories API: Coin categories with market data
- Exchanges API: Exchange data, tickers, and volume charts
- Derivatives API: Derivatives market data
- Entities API: Crypto treasury holdings
- NFTs API: NFT collections and market data
- Exchange Rates API: BTC exchange rates
- Search API: Search and trending data
- Global API: Global market statistics
- WebSocket API: Real-time data subscriptions
- Ping API: Server status and API usage
Error Handling ΒΆ
All API methods return an error as the last return value. Always check for errors:
data, err := cg.Coins().List(false)
if err != nil {
log.Printf("API error: %v", err)
return
}
Rate Limiting ΒΆ
Be aware of CoinGecko's rate limits:
- Free API: 10-50 calls/minute
- Pro API: Higher limits based on your plan
Implement caching to avoid hitting rate limits.
More Information ΒΆ
For detailed documentation and examples, visit: https://github.com/tigusigalpa/coingecko-go
CoinGecko API documentation: https://docs.coingecko.com
Index ΒΆ
- Constants
- type AssetPlatform
- type AssetPlatformsAPI
- type CategoriesAPI
- type Category
- type Client
- type ClientOption
- type CoinGecko
- func (cg *CoinGecko) AssetPlatforms() *AssetPlatformsAPI
- func (cg *CoinGecko) Categories() *CategoriesAPI
- func (cg *CoinGecko) Coins() *CoinsAPI
- func (cg *CoinGecko) Contract() *ContractAPI
- func (cg *CoinGecko) Derivatives() *DerivativesAPI
- func (cg *CoinGecko) Entities() *EntitiesAPI
- func (cg *CoinGecko) ExchangeRates() *ExchangeRatesAPI
- func (cg *CoinGecko) Exchanges() *ExchangesAPI
- func (cg *CoinGecko) Global() *GlobalAPI
- func (cg *CoinGecko) NFTs() *NFTsAPI
- func (cg *CoinGecko) Ping() *PingAPI
- func (cg *CoinGecko) Search() *SearchAPI
- func (cg *CoinGecko) Simple() *SimpleAPI
- func (cg *CoinGecko) WebSocket() *WebSocketAPI
- type CoinListItem
- type CoinOptions
- type CoinsAPI
- func (c *CoinsAPI) CirculatingSupplyChart(id string, days string, interval *string) (map[string]interface{}, error)
- func (c *CoinsAPI) CirculatingSupplyChartRange(id string, from int64, to int64) (map[string]interface{}, error)
- func (c *CoinsAPI) Coin(id string, options *CoinOptions) (map[string]interface{}, error)
- func (c *CoinsAPI) History(id string, date string, localization bool) (map[string]interface{}, error)
- func (c *CoinsAPI) List(includePlatform bool) ([]CoinListItem, error)
- func (c *CoinsAPI) MarketChart(id string, vsCurrency string, days string, options *MarketChartOptions) (map[string]interface{}, error)
- func (c *CoinsAPI) MarketChartRange(id string, vsCurrency string, from int64, to int64, precision *string) (map[string]interface{}, error)
- func (c *CoinsAPI) Markets(vsCurrency string, options *MarketsOptions) ([]map[string]interface{}, error)
- func (c *CoinsAPI) OHLC(id string, vsCurrency string, days string, precision *string) ([][]float64, error)
- func (c *CoinsAPI) RecentlyAdded() ([]map[string]interface{}, error)
- func (c *CoinsAPI) Tickers(id string, options *TickersOptions) (map[string]interface{}, error)
- func (c *CoinsAPI) TopGainersLosers(vsCurrency string, duration *string, topCoins *int) (map[string]interface{}, error)
- func (c *CoinsAPI) TotalSupplyChart(id string, days string, interval *string) (map[string]interface{}, error)
- func (c *CoinsAPI) TotalSupplyChartRange(id string, from int64, to int64) (map[string]interface{}, error)
- type ContractAPI
- func (c *ContractAPI) Coin(assetPlatform string, contractAddress string) (map[string]interface{}, error)
- func (c *ContractAPI) MarketChart(assetPlatform string, contractAddress string, vsCurrency string, days string) (map[string]interface{}, error)
- func (c *ContractAPI) MarketChartRange(assetPlatform string, contractAddress string, vsCurrency string, from int64, ...) (map[string]interface{}, error)
- type DerivativesAPI
- func (d *DerivativesAPI) Exchange(id string, includeTickers *string) (map[string]interface{}, error)
- func (d *DerivativesAPI) Exchanges(options *DerivativesExchangesOptions) ([]map[string]interface{}, error)
- func (d *DerivativesAPI) ExchangesList() ([]map[string]interface{}, error)
- func (d *DerivativesAPI) Tickers(includeTickers *string) ([]map[string]interface{}, error)
- type DerivativesExchangesOptions
- type EntitiesAPI
- func (e *EntitiesAPI) List() ([]map[string]interface{}, error)
- func (e *EntitiesAPI) TransactionHistory(entityID string, coinID string, options *TransactionHistoryOptions) (map[string]interface{}, error)
- func (e *EntitiesAPI) TreasuryByCoinID(coinID string) (map[string]interface{}, error)
- func (e *EntitiesAPI) TreasuryByEntityID(entityID string, coinID string) (map[string]interface{}, error)
- func (e *EntitiesAPI) TreasuryChart(entityID string, coinID string, days int) (map[string]interface{}, error)
- type ExchangeRatesAPI
- type ExchangeTickersOptions
- type ExchangesAPI
- func (e *ExchangesAPI) Exchange(id string) (map[string]interface{}, error)
- func (e *ExchangesAPI) List(options *ExchangesListOptions) ([]map[string]interface{}, error)
- func (e *ExchangesAPI) ListIDMap() ([]map[string]interface{}, error)
- func (e *ExchangesAPI) Tickers(id string, options *ExchangeTickersOptions) (map[string]interface{}, error)
- func (e *ExchangesAPI) VolumeChart(id string, days int) ([][]interface{}, error)
- func (e *ExchangesAPI) VolumeChartRange(id string, from int64, to int64) ([][]interface{}, error)
- type ExchangesListOptions
- type GlobalAPI
- type MarketChartOptions
- type MarketsOptions
- type NFTsAPI
- func (n *NFTsAPI) Collection(id string) (map[string]interface{}, error)
- func (n *NFTsAPI) CollectionByContract(assetPlatformID string, contractAddress string) (map[string]interface{}, error)
- func (n *NFTsAPI) List(options *NFTsListOptions) ([]map[string]interface{}, error)
- func (n *NFTsAPI) MarketChart(id string, days int) (map[string]interface{}, error)
- func (n *NFTsAPI) MarketChartByContract(assetPlatformID string, contractAddress string, days int) (map[string]interface{}, error)
- func (n *NFTsAPI) Markets(options *NFTsMarketsOptions) ([]map[string]interface{}, error)
- func (n *NFTsAPI) Tickers(id string) (map[string]interface{}, error)
- type NFTsListOptions
- type NFTsMarketsOptions
- type PingAPI
- type PingResponse
- type SearchAPI
- type SimpleAPI
- func (s *SimpleAPI) Price(ids []string, vsCurrencies []string, options *SimplePriceOptions) (map[string]map[string]interface{}, error)
- func (s *SimpleAPI) SupportedVsCurrencies() ([]string, error)
- func (s *SimpleAPI) TokenPrice(assetPlatform string, contractAddresses []string, vsCurrencies []string, ...) (map[string]map[string]interface{}, error)
- type SimplePriceOptions
- type TickersOptions
- type TokenPriceOptions
- type TransactionHistoryOptions
- type WebSocketAPI
- func (w *WebSocketAPI) CreateOnchainOHLCVSubscription(network string, poolAddress string, timeframe string) (string, error)
- func (w *WebSocketAPI) CreateOnchainSimpleTokenPriceSubscription(network string, addresses []string, vsCurrencies []string) (string, error)
- func (w *WebSocketAPI) CreateOnchainTradeSubscription(network string, poolAddress string) (string, error)
- func (w *WebSocketAPI) CreatePingMessage() (string, error)
- func (w *WebSocketAPI) CreateSimplePriceSubscription(coinIDs []string, vsCurrencies []string) (string, error)
- func (w *WebSocketAPI) CreateUnsubscribeMessage(channel string) (string, error)
- func (w *WebSocketAPI) GetWebSocketURL() string
- type WebSocketSubscription
Constants ΒΆ
const ( BaseURLFree = "https://api.coingecko.com/api/v3" BaseURLPro = "https://pro-api.coingecko.com/api/v3" )
const (
WebSocketURLPro = "wss://ws-pro.coingecko.com/v1"
)
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type AssetPlatform ΒΆ
type AssetPlatformsAPI ΒΆ
type AssetPlatformsAPI struct {
// contains filtered or unexported fields
}
func (*AssetPlatformsAPI) List ΒΆ
func (a *AssetPlatformsAPI) List(filter *string) ([]AssetPlatform, error)
func (*AssetPlatformsAPI) TokenLists ΒΆ
func (a *AssetPlatformsAPI) TokenLists(assetPlatformID string, page *int) (map[string]interface{}, error)
type CategoriesAPI ΒΆ
type CategoriesAPI struct {
// contains filtered or unexported fields
}
func (*CategoriesAPI) List ΒΆ
func (c *CategoriesAPI) List() ([]Category, error)
func (*CategoriesAPI) ListWithMarketData ΒΆ
func (c *CategoriesAPI) ListWithMarketData(order *string) ([]map[string]interface{}, error)
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
func NewClient ΒΆ
func NewClient(options ...ClientOption) *Client
type ClientOption ΒΆ
type ClientOption func(*Client)
func WithAPIKey ΒΆ
func WithAPIKey(apiKey string) ClientOption
func WithHTTPClient ΒΆ
func WithHTTPClient(httpClient *http.Client) ClientOption
func WithProAPI ΒΆ
func WithProAPI(isPro bool) ClientOption
func WithTimeout ΒΆ
func WithTimeout(timeout time.Duration) ClientOption
type CoinGecko ΒΆ
type CoinGecko struct {
// contains filtered or unexported fields
}
func New ΒΆ
func New(options ...ClientOption) *CoinGecko
func (*CoinGecko) AssetPlatforms ΒΆ
func (cg *CoinGecko) AssetPlatforms() *AssetPlatformsAPI
func (*CoinGecko) Categories ΒΆ
func (cg *CoinGecko) Categories() *CategoriesAPI
func (*CoinGecko) Contract ΒΆ
func (cg *CoinGecko) Contract() *ContractAPI
func (*CoinGecko) Derivatives ΒΆ
func (cg *CoinGecko) Derivatives() *DerivativesAPI
func (*CoinGecko) Entities ΒΆ
func (cg *CoinGecko) Entities() *EntitiesAPI
func (*CoinGecko) ExchangeRates ΒΆ
func (cg *CoinGecko) ExchangeRates() *ExchangeRatesAPI
func (*CoinGecko) Exchanges ΒΆ
func (cg *CoinGecko) Exchanges() *ExchangesAPI
func (*CoinGecko) WebSocket ΒΆ
func (cg *CoinGecko) WebSocket() *WebSocketAPI
type CoinListItem ΒΆ
type CoinOptions ΒΆ
type CoinsAPI ΒΆ
type CoinsAPI struct {
// contains filtered or unexported fields
}
func (*CoinsAPI) CirculatingSupplyChart ΒΆ
func (*CoinsAPI) CirculatingSupplyChartRange ΒΆ
func (*CoinsAPI) Coin ΒΆ
func (c *CoinsAPI) Coin(id string, options *CoinOptions) (map[string]interface{}, error)
func (*CoinsAPI) MarketChart ΒΆ
func (*CoinsAPI) MarketChartRange ΒΆ
func (*CoinsAPI) Markets ΒΆ
func (c *CoinsAPI) Markets(vsCurrency string, options *MarketsOptions) ([]map[string]interface{}, error)
func (*CoinsAPI) RecentlyAdded ΒΆ
func (*CoinsAPI) Tickers ΒΆ
func (c *CoinsAPI) Tickers(id string, options *TickersOptions) (map[string]interface{}, error)
func (*CoinsAPI) TopGainersLosers ΒΆ
func (*CoinsAPI) TotalSupplyChart ΒΆ
type ContractAPI ΒΆ
type ContractAPI struct {
// contains filtered or unexported fields
}
func (*ContractAPI) Coin ΒΆ
func (c *ContractAPI) Coin(assetPlatform string, contractAddress string) (map[string]interface{}, error)
func (*ContractAPI) MarketChart ΒΆ
func (*ContractAPI) MarketChartRange ΒΆ
type DerivativesAPI ΒΆ
type DerivativesAPI struct {
// contains filtered or unexported fields
}
func (*DerivativesAPI) Exchange ΒΆ
func (d *DerivativesAPI) Exchange(id string, includeTickers *string) (map[string]interface{}, error)
func (*DerivativesAPI) Exchanges ΒΆ
func (d *DerivativesAPI) Exchanges(options *DerivativesExchangesOptions) ([]map[string]interface{}, error)
func (*DerivativesAPI) ExchangesList ΒΆ
func (d *DerivativesAPI) ExchangesList() ([]map[string]interface{}, error)
type EntitiesAPI ΒΆ
type EntitiesAPI struct {
// contains filtered or unexported fields
}
func (*EntitiesAPI) List ΒΆ
func (e *EntitiesAPI) List() ([]map[string]interface{}, error)
func (*EntitiesAPI) TransactionHistory ΒΆ
func (e *EntitiesAPI) TransactionHistory(entityID string, coinID string, options *TransactionHistoryOptions) (map[string]interface{}, error)
func (*EntitiesAPI) TreasuryByCoinID ΒΆ
func (e *EntitiesAPI) TreasuryByCoinID(coinID string) (map[string]interface{}, error)
func (*EntitiesAPI) TreasuryByEntityID ΒΆ
func (e *EntitiesAPI) TreasuryByEntityID(entityID string, coinID string) (map[string]interface{}, error)
func (*EntitiesAPI) TreasuryChart ΒΆ
type ExchangeRatesAPI ΒΆ
type ExchangeRatesAPI struct {
// contains filtered or unexported fields
}
func (*ExchangeRatesAPI) Rates ΒΆ
func (e *ExchangeRatesAPI) Rates() (map[string]interface{}, error)
type ExchangeTickersOptions ΒΆ
type ExchangesAPI ΒΆ
type ExchangesAPI struct {
// contains filtered or unexported fields
}
func (*ExchangesAPI) Exchange ΒΆ
func (e *ExchangesAPI) Exchange(id string) (map[string]interface{}, error)
func (*ExchangesAPI) List ΒΆ
func (e *ExchangesAPI) List(options *ExchangesListOptions) ([]map[string]interface{}, error)
func (*ExchangesAPI) ListIDMap ΒΆ
func (e *ExchangesAPI) ListIDMap() ([]map[string]interface{}, error)
func (*ExchangesAPI) Tickers ΒΆ
func (e *ExchangesAPI) Tickers(id string, options *ExchangeTickersOptions) (map[string]interface{}, error)
func (*ExchangesAPI) VolumeChart ΒΆ
func (e *ExchangesAPI) VolumeChart(id string, days int) ([][]interface{}, error)
func (*ExchangesAPI) VolumeChartRange ΒΆ
func (e *ExchangesAPI) VolumeChartRange(id string, from int64, to int64) ([][]interface{}, error)
type ExchangesListOptions ΒΆ
type MarketChartOptions ΒΆ
type MarketsOptions ΒΆ
type NFTsAPI ΒΆ
type NFTsAPI struct {
// contains filtered or unexported fields
}
func (*NFTsAPI) Collection ΒΆ
func (*NFTsAPI) CollectionByContract ΒΆ
func (*NFTsAPI) List ΒΆ
func (n *NFTsAPI) List(options *NFTsListOptions) ([]map[string]interface{}, error)
func (*NFTsAPI) MarketChart ΒΆ
func (*NFTsAPI) MarketChartByContract ΒΆ
type NFTsListOptions ΒΆ
type NFTsMarketsOptions ΒΆ
type PingAPI ΒΆ
type PingAPI struct {
// contains filtered or unexported fields
}
func (*PingAPI) Ping ΒΆ
func (p *PingAPI) Ping() (*PingResponse, error)
type PingResponse ΒΆ
type PingResponse struct {
GeckoSays string `json:"gecko_says"`
}
type SearchAPI ΒΆ
type SearchAPI struct {
// contains filtered or unexported fields
}
type SimpleAPI ΒΆ
type SimpleAPI struct {
// contains filtered or unexported fields
}
func (*SimpleAPI) SupportedVsCurrencies ΒΆ
func (*SimpleAPI) TokenPrice ΒΆ
type SimplePriceOptions ΒΆ
type TickersOptions ΒΆ
type TokenPriceOptions ΒΆ
type WebSocketAPI ΒΆ
type WebSocketAPI struct {
// contains filtered or unexported fields
}
func (*WebSocketAPI) CreateOnchainOHLCVSubscription ΒΆ
func (*WebSocketAPI) CreateOnchainSimpleTokenPriceSubscription ΒΆ
func (*WebSocketAPI) CreateOnchainTradeSubscription ΒΆ
func (w *WebSocketAPI) CreateOnchainTradeSubscription(network string, poolAddress string) (string, error)
func (*WebSocketAPI) CreatePingMessage ΒΆ
func (w *WebSocketAPI) CreatePingMessage() (string, error)
func (*WebSocketAPI) CreateSimplePriceSubscription ΒΆ
func (w *WebSocketAPI) CreateSimplePriceSubscription(coinIDs []string, vsCurrencies []string) (string, error)
func (*WebSocketAPI) CreateUnsubscribeMessage ΒΆ
func (w *WebSocketAPI) CreateUnsubscribeMessage(channel string) (string, error)
func (*WebSocketAPI) GetWebSocketURL ΒΆ
func (w *WebSocketAPI) GetWebSocketURL() string