Documentation ¶
Index ¶
Constants ¶
const ( // Name is the name of the Coingecko provider. Name = "coingecko_api" // URL is the base URL for the CoinGecko API. This URL does not require // an API key but may be rate limited. URL = "https://api.coingecko.com/api/v3" // APIURL is the base URL for the CoinGecko API. This URL requires an API // key and is not rate limited. APIURL = "https://pro-api.coingecko.com/api/v3" // APIKeyHeader is the header used to pass the API key to the CoinGecko API. APIKeyHeader = "x-cg-pro-api-key" //nolint // PairPriceEndpoint is the URL used to fetch the price of a list of currency // pairs. The ids are the base currencies and the vs_currencies are the quote // currencies. Note that the IDs and vs_currencies are comma separated but are // not 1:1 in their representation. PairPriceEndpoint = "/simple/price?ids=%s&vs_currencies=%s" // Precision is the precision of the price returned by the CoinGecko API. All // results are returned with 18 decimal places and are expected to be converted // to the appropriate precision by the parser. Precision = "&precision=18" // TickerSeparator is the formatter of the ticker that is used to fetch the price // of a currency pair. The first currency is the base currency and the second // currency is the quote currency. TickerSeparator = "/" )
Variables ¶
var DefaultAPIConfig = config.APIConfig{ Name: Name, Atomic: true, Enabled: true, Timeout: 3000 * time.Millisecond, Interval: 20 * time.Second, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{{URL: URL}}, }
DefaultAPIConfig is the default configuration for the CoinGecko API.
Functions ¶
func NewAPIHandler ¶
func NewAPIHandler( api config.APIConfig, ) (types.PriceAPIDataHandler, error)
NewAPIHandler returns a new CoinGecko PriceAPIDataHandler.
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
APIHandler implements the PriceAPIDataHandler interface for CoinGecko.
func (*APIHandler) CreateURL ¶
func (h *APIHandler) CreateURL( tickers []types.ProviderTicker, ) (string, error)
CreateURL returns the URL that is used to fetch data from the CoinGecko API for the given tickers. The CoinGecko API supports fetching spot prices for multiple tickers in a single request.
func (*APIHandler) ParseResponse ¶
func (h *APIHandler) ParseResponse( tickers []types.ProviderTicker, resp *http.Response, ) types.PriceResponse
ParseResponse parses the response from the CoinGecko API. The response is expected to match every base currency with every quote currency. As such, we need to filter out the responses that are not expected. Note that the response will only return a response for the inputted tickers.
type CoinGeckoResponse ¶
CoinGeckoResponse is the response returned by the CoinGecko API. The response format looks like the following:
{ "bitcoin": { "usd": 43808.30302432908, "btc": 1 }, "ethereum": { "usd": 2240.4139379890357, "btc": 0.05113686971792297 } }