Skip to content

Golang wrapper for CoinGecko and GeckoTerminal API.

License

Notifications You must be signed in to change notification settings

bufdata/coingecko-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoinGecko API

Go Version PkgGoDev Go Report Card Codecov license Code Lint Unit Test Build Status

This library contains two apis:

Installation

go get -u github.com/bufdata/coingecko-api

Usage

CoinGecko

For free API, you can provide an API Key or not:

package main

import (
	"context"
	"log/slog"

	"github.com/bufdata/coingecko-api/coingecko"
)

func main() {
	api := coingecko.NewCoinGecko("your_api_key", false, nil)
	data, err := api.ListCoinsInfo(context.Background(), true)
	if err != nil {
		slog.Error("failed to call ListCoinsInfo", "error", err)
	}
	slog.Info("call ListSupportedCoinsInfo successfully", "response data", (*data)[0])
}

For users with Pro API Key:

package main

import (
	"context"
	"log/slog"

	"github.com/bufdata/coingecko-api/coingecko"
)

func main() {
	api := coingecko.NewCoinGecko("your_api_key", true, nil)
	data, err := api.ListCoinsInfo(context.Background(), true)
	if err != nil {
		slog.Error("failed to call ListCoinsInfo", "error", err)
	}
	slog.Info("call ListSupportedCoinsInfo successfully", "response data", (*data)[0])
}

If you use coingecko library in production, you might need to set your own http.Client param.

This library has covered all APIs. For detailed APIs info, you can read CoinGecko docs.

Note

The methods in coingecko/paid_methods.go and coingecko/enterprise_methods.go are not tested, so if you find there are some bugs in them, you can raise pr or issue.

GeckoTerminal

package main

import (
	"context"
	"log/slog"

	"github.com/bufdata/coingecko-api/geckoterminal"
)

func main() {
	api := geckoterminal.NewGeckoTerminal(nil)
	data, err := api.GetNetworks(context.Background(), 0)
	if err != nil {
		slog.Error("failed to call GetNetworks", "error", err)
	}
	slog.Info("call GetNetworks successfully", "response data", *data)
}

If you use geckoterminal library in production, you might need to set your own http.Client param.

This library has covered all APIs. For detailed APIs info, you can read GeckoTerminal API.

License

MIT