goingecko

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 24 Imported by: 0

README

Goingecko

Coingecko API client for golang.

goingecko

Endpoints

Endpoint Status Function
/ping Ping
/simple/price SimplePrice
/simple/token_price/{id} SimpleTokenPrice
/simple/supported_vs_currencies SimpleSupportedVsCurrency
/coins/list CoinsList
/coins/markets CoinsMarket
/coins/{id} CoinsId
/coins/{id}/tickers CoinsIdTickers
/coins/{id}/history CoinsIdHistory
/coins/{id}/market_chart CoinsIdMarketChart
/coins/{id}/market_chart/range CoinsIdMarketChartRange
/coins/{id}/ohlc CoinsOhlc
/coins/{id}/contract/{contract_address} ContractInfo
/coins/{id}/contract/{contract_address}/market_chart/ ContractMarketChart
/coins/{id}/contract/{contract_address}/market_chart/range ContractMarketChartRange
/asset_platforms AssetPlatforms
/coins/categories/list CategoriesList
/coins/categories/ Categories
/exchanges Exchanges
/exchanges/list ExchangesList
/exchanges/{id} ExchangesId
/exchanges/{id}/tickers ExchangesIdTickers
/exchanges/{id}/volume_chart ExchangesIdVolumeChart
/derivaties Derivatives
/derivaties/exchanges DerivativesExchanges
/derivaties/exchanges/{id} DerivativesExchangesId
/derivaties/exchanges/list DerivativesExchangesList
/nfts/list NftsList
/nfts/{id} NftsId
/nfts/{asset_platform_id}/contract/{contract_address} NftsContract
/exchange_rates ExchangeRates
/search Search
/search/trending Trending
/global Global
/global/decentralized_finance_defi DecentrilizedFinanceDEFI
/companies/public_treasury/{coin_id} PublicTreasuryCoinId

Usage

package main

import (
	"fmt"

	"github.com/JulianToledano/goingecko"
)

func main() {
	cgClient := goingecko.NewClient(nil, "")
	defer cgClient.Close()

	data, err := cgClient.CoinsId("bitcoin", true, true, true, false, false, false)
	if err != nil {
		fmt.Print("Somethig went wrong...")
		return
	}
	fmt.Printf("Bitcoin price is: %f$", data.MarketData.CurrentPrice.Usd)
}

Check dir examples for more.

Thanks

This repo is based somehow in superoo7/go-gecko work.

Image was created with Gophers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseURL    = fmt.Sprintf("https://api.coingecko.com/api/%s", version)
	ProBaseURL = fmt.Sprintf("https://pro-api.coingecko.com/api/%s", version)
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, apiKey string, isPro ...bool) *Client

func (*Client) AssetPlatforms

func (c *Client) AssetPlatforms(ctx context.Context, filter string) (*assetPlatforms.AssetPlatforms, error)

func (*Client) Categories

Categories List all categories with market data Cache / Update Frequency: every 5 minutes Parameters: order: valid values: market_cap_desc (default), market_cap_asc, name_desc, name_asc, market_cap_change_24h_desc and market_cap_change_24h_asc

func (*Client) CategoriesList

func (c *Client) CategoriesList(ctx context.Context) (*categories.CategoriesList, error)

CategoriesList List all categories Cache / Update Frequency: every 5 minutes

func (*Client) Close

func (c *Client) Close()

func (*Client) CoinsId

func (c *Client) CoinsId(ctx context.Context, id string, localization, tickers, marketData, communityData, developerData, sparkline bool) (*coins.CoinID, error)

func (*Client) CoinsIdHistory

func (c *Client) CoinsIdHistory(ctx context.Context, id, date string, localization bool) (*coins.History, error)

func (*Client) CoinsIdMarketChart

func (c *Client) CoinsIdMarketChart(ctx context.Context, id, currency, days, interval string) (*types.MarketChart, error)

func (*Client) CoinsIdMarketChartRange

func (c *Client) CoinsIdMarketChartRange(ctx context.Context, id, currency, from, to string) (*types.MarketChart, error)

func (*Client) CoinsIdTickers

func (c *Client) CoinsIdTickers(ctx context.Context, id, exchangeId, includeExchangeLogo, page, order, depth string) (*coins.Tickers, error)

func (*Client) CoinsList

func (c *Client) CoinsList(ctx context.Context) ([]*coins.CoinInfo, error)

func (*Client) CoinsMarket

func (c *Client) CoinsMarket(ctx context.Context, currency string, ids []string, category string, order string, perPage, page string, sparkline bool, priceChange []string) ([]*coins.Market, error)

func (*Client) CoinsOhlc

func (c *Client) CoinsOhlc(ctx context.Context, id, currency, days string) (*coins.Ohlc, error)

func (*Client) ContractInfo

func (c *Client) ContractInfo(ctx context.Context, id, contractAddress string) (*contract.ContractAddressInfo, error)

func (*Client) ContractMarketChart

func (c *Client) ContractMarketChart(ctx context.Context, id, contractAddress, vsCurrency, days string) (*types.MarketChart, error)

func (*Client) ContractMarketChartRange

func (c *Client) ContractMarketChartRange(ctx context.Context, id, contractAddress, vsCurrency, from, to string) (*types.MarketChart, error)

func (*Client) DecentralizedFinanceDEFI

func (c *Client) DecentralizedFinanceDEFI(ctx context.Context) (*global.Defi, error)

func (*Client) Derivatives

func (c *Client) Derivatives(ctx context.Context) ([]derivatives.Derivative, error)

Derivatives List all derivative tickers. Note: 'open_interest' and 'volume_24h' data are in USD Cache / Update Frequency: every 30 seconds

func (*Client) DerivativesExchanges

func (c *Client) DerivativesExchanges(ctx context.Context, order string, perPage, page int32) ([]derivatives.Exchange, error)

DerivativesExchanges List all derivative exchanges.

Cache / Update Frequency: every 60 seconds Parameters:

order(string) - order results using following params name_asc,name_desc,open_interest_btc_asc,
				open_interest_btc_desc,trade_volume_24h_btc_asc,trade_volume_24h_btc_desc

perPage(integer) - Total results per page page(integer) - Page through results

func (*Client) DerivativesExchangesId

func (c *Client) DerivativesExchangesId(ctx context.Context, id, includeTickers string) (*derivatives.ExchangeId, error)

DerivativesExchangesId show derivative exchange data

Dictionary:

last: latest unconverted price in the respective pair target currency
volume: unconverted 24h trading volume in the respective pair target currency
converted_last: latest converted price in BTC, ETH, and USD
converted_volume: converted 24h trading volume in BTC, ETH, and USD

Cache / Update Frequency: every 30 seconds Parameters:

id*(string) - pass the exchange id (can be obtained from derivatives/exchanges/list) eg. bitmex
includeTickers(string) - ['all', 'unexpired'] - expired to show unexpired tickers, all to list all tickers,
						 leave blank to omit tickers data in response

func (*Client) DerivativesExchangesList

func (c *Client) DerivativesExchangesList(ctx context.Context) ([]derivatives.DerivativesListItem, error)

DerivativesExchangesList List all derivative exchanges name and identifier.

Cache / Update Frequency: every 5 minutes

func (*Client) ExchangeRates

func (c *Client) ExchangeRates(ctx context.Context) (*exchangeRates.Rates, error)

func (*Client) Exchanges

func (c *Client) Exchanges(ctx context.Context, perPage, page string) (*exchanges.ExchangesList, error)

Exchanges List all exchanges Cache / Update Frequency: every 60 seconds Parameters per_page (string) Total results per page:

Valid values: 1...250
Total results per page
Default value:: 100

page (string) page through results

func (*Client) ExchangesId

func (c *Client) ExchangesId(ctx context.Context, id string) (*exchanges.ExchangeWithTicker, error)

ExchangesId Get exchange volume in BTC and tickers. For derivatives (e.g. bitmex, binance_futures), please use /derivatives/exchange/{id} endpoint.

IMPORTANT: Ticker object is limited to 100 items, to get more tickers, use /exchanges/{id}/tickers Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for more than 8 hours. Ticker is_anomaly is true if ticker's price is outliered by our system. You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide)

Dictionary:

last: latest unconverted price in the respective pair target currency volume: unconverted 24h trading volume in the respective pair target currency converted_last: latest converted price in BTC, ETH, and USD converted_volume: converted 24h trading volume in BTC, ETH, and USD timestamp: returns the last time that the price has changed last_traded_at: returns the last time that the price has changed last_fetch_at: returns the last time we call the API Cache / Update Frequency: every 60 seconds

func (*Client) ExchangesIdTickers

func (c *Client) ExchangesIdTickers(ctx context.Context, id, coinIds, includeExchangeLogo string, page int32, depth, order string) (*exchanges.Tickers, error)

ExchangesIdTickers Get exchange tickers (paginated) IMPORTANT: Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for more than 8 hours. Ticker is_anomaly is true if ticker's price is outliered by our system. You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide)

Dictionary:

last: latest unconverted price in the respective pair target currency volume: unconverted 24h trading volume in the respective pair target currency converted_last: latest converted price in BTC, ETH, and USD converted_volume: converted 24h trading volume in BTC, ETH, and USD timestamp: returns the last time that the price has changed last_traded_at: returns the last time that the price has changed last_fetch_at: returns the last time we call the API Cache / Update Frequency: every 60 seconds Parameters:

id* - string - pass the exchange id (can be obtained from /exchanges/list) eg. binance
coinIds - string - filter tickers by coin_ids (ref: v3/coins/list)
includeExchangeLogo - string - flag to show exchange_logo. valid values: true, false
page - integer - Page through results
depth - string - lag to show 2% orderbook depth. i.e., cost_to_move_up_usd and cost_to_move_down_usd. valid values: true, false
order - string - valid values: trust_score_desc (default), trust_score_asc and volume_desc

func (*Client) ExchangesIdVolumeChart

func (c *Client) ExchangesIdVolumeChart(ctx context.Context, id, days string) ([]exchanges.Volume, error)

ExchangesIdVolumeChart Get 24 hour rolling trading volume data (in BTC) for a given exchange. Data granularity is automatic (cannot be adjusted)

1 day = 10-minutely
2-90 days = hourly
91 days above = daily

Note: exclusive endpoint is available for paid users to query more than 1 year of historical data

Cache / Update Frequency: every 60 seconds Parameters: id* - string - pass the exchange id (can be obtained from /exchanges/list) eg. binance days* - string - Data up to number of days ago (1/7/14/30/90/180/365)

func (*Client) ExchangesList

func (c *Client) ExchangesList(ctx context.Context) ([]exchanges.ExchangeId, error)

ExchangesList Use this to obtain all the markets' id in order to make API calls Cache / Update Frequency: every 5 minutes

func (*Client) Global

func (c *Client) Global(ctx context.Context) (*global.Global, error)

func (*Client) MakeReq

func (c *Client) MakeReq(ctx context.Context, url string) ([]byte, error)

MakeReq HTTP request helper

func (*Client) NftsContract

func (c *Client) NftsContract(ctx context.Context, assetPlatform, contract string) (*nfts.NftId, error)

NftsContract

func (*Client) NftsId

func (c *Client) NftsId(ctx context.Context, id string) (*nfts.NftId, error)

NftsId Get current data (name, price_floor, volume_24h ...) for an NFT collection. native_currency (string) is only a representative of the currency.

Cache / Update Frequency: every 60 seconds Parameters: id*(string) - id of nft collection (can be obtained from /nfts/list)

func (*Client) NftsList

func (c *Client) NftsList(ctx context.Context, order, assetPlatformId string, perPage, page int32) ([]nfts.Nft, error)

NftsList Use this to obtain all the NFT ids in order to make API calls, paginated to 100 items.

Cache / Update Frequency: every 5 minutes Parameters: order(string) - valid values: h24_volume_native_asc, h24_volume_native_desc, floor_price_native_asc, floor_price_native_desc, market_cap_native_asc, market_cap_native_desc, market_cap_usd_asc, market_cap_usd_desc assetPlatformId(string) - The id of the platform issuing tokens (See asset_platforms endpoint for list of options) per_page(integer) - Valid values: 1..250. Total results per page page(integer) - Page through results

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (*ping.Ping, error)

Ping /ping endpoint

func (*Client) PublicTreasuryCoinId

func (c *Client) PublicTreasuryCoinId(ctx context.Context, id string) (*companies.Treasury, error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (*search.Search, error)

Search for coins, categories and markets listed on CoinGecko ordered by largest Market Cap first.

Cache / Update Frequency: every 15 minutes

func (*Client) SimplePrice

func (c *Client) SimplePrice(ctx context.Context, ids, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.Price, error)

func (*Client) SimpleSupportedVsCurrency

func (c *Client) SimpleSupportedVsCurrency(ctx context.Context) (*simple.SupportedVsCurrency, error)

func (*Client) SimpleTokenPrice

func (c *Client) SimpleTokenPrice(ctx context.Context, id, contractAddresses, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.TokenPrice, error)

func (*Client) Trending

func (c *Client) Trending(ctx context.Context) (*trending.Trending, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL