├── backlog.md ├── coins ├── ohlc.go ├── list.go ├── tickers.go ├── history.go ├── statusUpdates.go ├── id.go └── markets.go ├── images └── goin.png ├── simple ├── supportedVsCurrency.go ├── price.go └── tokenPrice.go ├── go.mod ├── ping └── ping.go ├── types ├── marketChart.go └── types.go ├── assetPlatforms └── assetPlatforms.go ├── test ├── search_test.go ├── trending_test.go ├── exchangeRates_test.go ├── companies_test.go ├── goingecko_test.go ├── assetPlatforms_test.go ├── global_test.go ├── categories_test.go ├── simple_test.go ├── nfts_test.go ├── derivatives_test.go ├── contract_test.go ├── exchanges_test.go └── coins_test.go ├── search └── search.go ├── trending.go ├── examples ├── bitcoinPrice.go ├── pro.go └── checkTrending.go ├── trending └── trending.go ├── exchangeRates.go ├── global ├── defi.go └── global.go ├── companies.go ├── .gitignore ├── assetPlatforms.go ├── categories └── categories.go ├── companies └── companies.go ├── search.go ├── global.go ├── LICENSE ├── categories.go ├── endpoints.go ├── contract.go ├── client.go ├── exchangeRates └── exchangeRates.go ├── simple.go ├── nfts.go ├── derivatives └── derivatives.go ├── nfts └── nfts.go ├── derivatives.go ├── exchanges └── exchanges.go ├── contract └── contractAddress.go ├── README.md ├── coins.go └── exchanges.go /backlog.md: -------------------------------------------------------------------------------- 1 | # Backlog 2 | -------------------------------------------------------------------------------- /coins/ohlc.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | type Ohlc [][]float64 4 | -------------------------------------------------------------------------------- /images/goin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hey/goingecko/main/images/goin.png -------------------------------------------------------------------------------- /simple/supportedVsCurrency.go: -------------------------------------------------------------------------------- 1 | package simple 2 | 3 | type SupportedVsCurrency []string 4 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/JulianToledano/goingecko 2 | 3 | go 1.21 4 | 5 | toolchain go1.21.0 6 | -------------------------------------------------------------------------------- /ping/ping.go: -------------------------------------------------------------------------------- 1 | package ping 2 | 3 | type Ping struct { 4 | GeckoSays string `json:"gecko_says"` 5 | } 6 | -------------------------------------------------------------------------------- /simple/price.go: -------------------------------------------------------------------------------- 1 | package simple 2 | 3 | type Price map[string]PriceValues 4 | type PriceValues map[string]float64 5 | -------------------------------------------------------------------------------- /simple/tokenPrice.go: -------------------------------------------------------------------------------- 1 | package simple 2 | 3 | type TokenPrice map[string]TokenValues 4 | type TokenValues map[string]float64 5 | -------------------------------------------------------------------------------- /coins/list.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | type CoinInfo struct { 4 | ID string `json:"id"` 5 | Symbol string `json:"symbol"` 6 | Name string `json:"name"` 7 | } 8 | -------------------------------------------------------------------------------- /coins/tickers.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type Tickers struct { 6 | Name string `json:"name"` 7 | Tickers []types.Ticker `json:"tickers"` 8 | } 9 | -------------------------------------------------------------------------------- /types/marketChart.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type MarketChart struct { 4 | Prices [][]float64 `json:"prices"` 5 | MarketCaps [][]float64 `json:"market_caps"` 6 | TotalVolumes [][]float64 `json:"total_volumes"` 7 | } 8 | -------------------------------------------------------------------------------- /assetPlatforms/assetPlatforms.go: -------------------------------------------------------------------------------- 1 | package assetPlatforms 2 | 3 | type AssetPlatforms []Asset 4 | 5 | type Asset struct { 6 | ID string `json:"id"` 7 | ChainIdentifier int64 `json:"chain_identifier"` 8 | Name string `json:"name"` 9 | ShortName string `json:"shortName"` 10 | NativeCoinId string `json:"native_coin_id"` 11 | } 12 | -------------------------------------------------------------------------------- /test/search_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestSearch(t *testing.T) { 9 | cgClient := goingecko.NewClient(nil, "") 10 | data, err := cgClient.Search("bitcoin") 11 | if data == nil { 12 | t.Errorf("Error") 13 | } 14 | if err != nil { 15 | t.Errorf("Error: %s", err) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/trending_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestTrending(t *testing.T) { 10 | 11 | cgClient := goingecko.NewClient(nil, "") 12 | 13 | r, err := cgClient.Trending() 14 | if r == nil { 15 | t.Errorf("Error") 16 | } 17 | if err != nil { 18 | t.Errorf("Error: %s", err) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/exchangeRates_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestExchangeRates(t *testing.T) { 10 | 11 | cgClient := goingecko.NewClient(nil, "") 12 | 13 | r, err := cgClient.ExchangeRates() 14 | if r == nil { 15 | t.Errorf("Error") 16 | } 17 | if err != nil { 18 | t.Errorf("Error: %s", err) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/companies_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestPublicTreasuryCoinId(t *testing.T) { 9 | cgClient := goingecko.NewClient(nil, "") 10 | data, err := cgClient.PublicTreasuryCoinId("bitcoin") 11 | if data == nil { 12 | t.Errorf("Error") 13 | } 14 | if err != nil { 15 | t.Errorf("Error: %s", err) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/goingecko_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/JulianToledano/goingecko" 8 | ) 9 | 10 | func TestCoins(t *testing.T) { 11 | coin := "bitcoin" 12 | 13 | cgClient := goingecko.NewClient(nil, "") 14 | 15 | coinData, _ := cgClient.CoinsId(coin, true, true, true, true, true, true) 16 | fmt.Println(coinData.MarketData.CurrentPrice.Usd) 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/assetPlatforms_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestAssetPlatforms(t *testing.T) { 9 | 10 | cgClient := goingecko.NewClient(nil, "") 11 | 12 | assetData, err := cgClient.AssetPlatforms("") 13 | if assetData == nil { 14 | t.Errorf("Error") 15 | } 16 | if err != nil { 17 | t.Errorf("Error: %s", err) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /search/search.go: -------------------------------------------------------------------------------- 1 | package search 2 | 3 | type Search struct { 4 | Coins []Item `json:"coins"` 5 | } 6 | 7 | type Item struct { 8 | ID string `json:"id"` 9 | Name string `json:"name"` 10 | ApiSymbol string `json:"api_symbol"` 11 | Symbol string `json:"symbol"` 12 | MarketCapRank int64 `json:"market_cap_rank"` 13 | Thumb string `json:"thumb"` 14 | Large string `json:"large"` 15 | } 16 | -------------------------------------------------------------------------------- /trending.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/JulianToledano/goingecko/trending" 7 | ) 8 | 9 | func (c *Client) Trending() (*trending.Trending, error) { 10 | resp, err := c.MakeReq(c.getTrendingURL()) 11 | if err != nil { 12 | return nil, err 13 | } 14 | 15 | var data *trending.Trending 16 | err = json.Unmarshal([]byte(resp), &data) 17 | if err != nil { 18 | return nil, err 19 | } 20 | return data, nil 21 | } 22 | -------------------------------------------------------------------------------- /examples/bitcoinPrice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func main() { 10 | cgClient := goingecko.NewClient(nil, "") 11 | defer cgClient.Close() 12 | 13 | data, err := cgClient.CoinsId("bitcoin", true, true, true, false, false, false) 14 | if err != nil { 15 | fmt.Print("Somethig went wrong...") 16 | return 17 | } 18 | fmt.Printf("Bitcoin price is: %f$", data.MarketData.CurrentPrice.Usd) 19 | } 20 | -------------------------------------------------------------------------------- /examples/pro.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func main() { 10 | cgClient := goingecko.NewClient(nil, "pro api key", true) 11 | defer cgClient.Close() 12 | 13 | data, err := cgClient.CoinsId("bitcoin", true, true, true, false, false, false) 14 | if err != nil { 15 | fmt.Print("Somethig went wrong...") 16 | return 17 | } 18 | fmt.Printf("Bitcoin price is: %f$", data.MarketData.CurrentPrice.Usd) 19 | } 20 | -------------------------------------------------------------------------------- /trending/trending.go: -------------------------------------------------------------------------------- 1 | package trending 2 | 3 | type Trending struct { 4 | Coins []coin `json:"coins"` 5 | } 6 | 7 | type coin struct { 8 | Item item `json:"item"` 9 | } 10 | 11 | type item struct { 12 | ID string `json:"id"` 13 | Name string `json:"name"` 14 | Symbol string `json:"symbol"` 15 | MarketCapRank int32 `json:"market_cap_rank"` 16 | Thumb string `json:"thumb"` 17 | Large string `json:"large"` 18 | Score float64 `json:"score"` 19 | } 20 | -------------------------------------------------------------------------------- /exchangeRates.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | "github.com/JulianToledano/goingecko/exchangeRates" 8 | ) 9 | 10 | func (c *Client) ExchangeRates() (*exchangeRates.Rates, error) { 11 | rUrl := fmt.Sprintf("%s", c.getExchangeRatesURL()) 12 | resp, err := c.MakeReq(rUrl) 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | var data *exchangeRates.Rates 18 | err = json.Unmarshal([]byte(resp), &data) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return data, nil 23 | } 24 | -------------------------------------------------------------------------------- /global/defi.go: -------------------------------------------------------------------------------- 1 | package global 2 | 3 | type Defi struct { 4 | Data defiInfo `json:"data"` 5 | } 6 | 7 | type defiInfo struct { 8 | DefiMarketCap string `json:"defi_market_cap"` 9 | EthMarketCap string `json:"eth_market_cap"` 10 | DefiToEthRatio string `json:"defi_to_eth_ratio"` 11 | TradingVolume24h string `json:"trading_volume_24h"` 12 | Defi_dominance string `json:"defi_dominance"` 13 | TopCoinName string `json:"top_coin_name"` 14 | TopCoinDefiDominance float64 `json:"top_coin_defi_dominance"` 15 | } 16 | -------------------------------------------------------------------------------- /companies.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | "github.com/JulianToledano/goingecko/companies" 8 | ) 9 | 10 | func (c *Client) PublicTreasuryCoinId(id string) (*companies.Treasury, error) { 11 | rUrl := fmt.Sprintf("%s/public_treasury/%s", c.getCompaniesURL(), id) 12 | resp, err := c.MakeReq(rUrl) 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | var data *companies.Treasury 18 | err = json.Unmarshal([]byte(resp), &data) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return data, nil 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Go ### 2 | # Binaries for programs and plugins 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, built with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | # vendor/ 17 | 18 | ### Go Patch ### 19 | /vendor/ 20 | /Godeps/ 21 | 22 | ### vscode ### 23 | .vscode/* 24 | !.vscode/settings.json 25 | !.vscode/tasks.json 26 | !.vscode/launch.json 27 | !.vscode/extensions.json 28 | *.code-workspace 29 | 30 | .idea -------------------------------------------------------------------------------- /test/global_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestGlobal(t *testing.T) { 10 | 11 | cgClient := goingecko.NewClient(nil, "") 12 | 13 | r, err := cgClient.Global() 14 | if r == nil { 15 | t.Errorf("Error") 16 | } 17 | if err != nil { 18 | t.Errorf("Error: %s", err) 19 | } 20 | } 21 | 22 | func TestDefi(t *testing.T) { 23 | 24 | cgClient := goingecko.NewClient(nil, "") 25 | 26 | r, err := cgClient.DecentrilizedFinanceDEFI() 27 | if r == nil { 28 | t.Errorf("Error") 29 | } 30 | if err != nil { 31 | t.Errorf("Error: %s", err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/checkTrending.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func main() { 10 | cgClient := goingecko.NewClient(nil, "") 11 | defer cgClient.Close() 12 | 13 | treding, err := cgClient.Trending() 14 | if err != nil { 15 | fmt.Print("Something went wrong...") 16 | return 17 | } 18 | for _, coin := range treding.Coins { 19 | coinData, err := cgClient.CoinsId(coin.Item.ID, false, false, true, false, false, false) 20 | if err != nil { 21 | fmt.Printf("Error: %v", err) 22 | } 23 | fmt.Printf("Name: %s | Symbol: %s | Price: %f\n", coin.Item.Name, coin.Item.Symbol, coinData.MarketData.CurrentPrice.Usd) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /assetPlatforms.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/assetPlatforms" 9 | ) 10 | 11 | func (c *Client) AssetPlatforms(filter string) (*assetPlatforms.AssetPlatforms, error) { 12 | params := url.Values{} 13 | 14 | if filter != "" { 15 | params.Add("filter", filter) 16 | } 17 | 18 | rUrl := fmt.Sprintf("%s?%s", c.getAssetPlatformsURL(), params.Encode()) 19 | resp, err := c.MakeReq(rUrl) 20 | if err != nil { 21 | return nil, err 22 | } 23 | var data *assetPlatforms.AssetPlatforms 24 | err = json.Unmarshal(resp, &data) 25 | if err != nil { 26 | return nil, err 27 | } 28 | return data, nil 29 | } 30 | -------------------------------------------------------------------------------- /test/categories_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestCategoriesList(t *testing.T) { 9 | 10 | cgClient := goingecko.NewClient(nil, "") 11 | 12 | categoriesList, err := cgClient.CategoriesList() 13 | if categoriesList == nil { 14 | t.Errorf("Error") 15 | } 16 | if err != nil { 17 | t.Errorf("Error: %s", err) 18 | } 19 | } 20 | 21 | func TestCategories(t *testing.T) { 22 | 23 | cgClient := goingecko.NewClient(nil, "") 24 | 25 | categoriesList, err := cgClient.Categories("market_cap_desc") 26 | if categoriesList == nil { 27 | t.Errorf("Error") 28 | } 29 | if err != nil { 30 | t.Errorf("Error: %s", err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /categories/categories.go: -------------------------------------------------------------------------------- 1 | package categories 2 | 3 | type CategoriesList []Category 4 | 5 | type Category struct { 6 | CategoryId string `json:"category_id"` 7 | Name string `json:"name"` 8 | } 9 | 10 | type CategoriesWithMarketDataList []CategoryWithMarketData 11 | 12 | type CategoryWithMarketData struct { 13 | ID string `json:"id"` 14 | Name string `json:"name"` 15 | MarketCap float64 `json:"market_cap"` 16 | MarketCapChange24h float64 `json:"market_cap_change_24h"` 17 | Content string `json:"content"` 18 | Top3Coins []string `json:"top_3_coins"` 19 | Volume24h float64 `json:"volume_24h"` 20 | UpdatedAt string `json:"updated_at"` 21 | } 22 | -------------------------------------------------------------------------------- /companies/companies.go: -------------------------------------------------------------------------------- 1 | package companies 2 | 3 | type Treasury struct { 4 | TotalHoldings float64 `json:"total_holdings"` 5 | TotalValueUsd float64 `json:"total_value_usd"` 6 | MarketCapDominance float64 `json:"market_cap_dominance"` 7 | Companies []Companies `json:"companies"` 8 | } 9 | 10 | type Companies struct { 11 | Name string `json:"name"` 12 | Symbol string `json:"symbol"` 13 | Country string `json:"country"` 14 | TotalHoldings int64 `json:"total_holdings"` 15 | TotalEntryValueUsd int64 `json:"total_entry_value_usd"` 16 | TotalCurrentValueUsd int64 `json:"total_current_value_usd"` 17 | PercentageOfTotalSupply float64 `json:"percentage_of_total_supply"` 18 | } 19 | -------------------------------------------------------------------------------- /search.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/search" 9 | ) 10 | 11 | // Search for coins, categories and markets listed on CoinGecko ordered by largest Market Cap first. 12 | // 13 | // Cache / Update Frequency: every 15 minutes 14 | func (c *Client) Search(query string) (*search.Search, error) { 15 | params := url.Values{} 16 | if query != "" { 17 | params.Add("query", query) 18 | } 19 | 20 | rUrl := fmt.Sprintf("%s?%s", c.getSearchURL(), params.Encode()) 21 | resp, err := c.MakeReq(rUrl) 22 | if err != nil { 23 | return nil, err 24 | } 25 | 26 | var data *search.Search 27 | err = json.Unmarshal(resp, &data) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | return data, nil 33 | } 34 | -------------------------------------------------------------------------------- /global.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | "github.com/JulianToledano/goingecko/global" 8 | ) 9 | 10 | func (c *Client) Global() (*global.Global, error) { 11 | resp, err := c.MakeReq(c.getGlobalURL()) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | var data *global.Global 17 | err = json.Unmarshal([]byte(resp), &data) 18 | if err != nil { 19 | return nil, err 20 | } 21 | return data, nil 22 | } 23 | 24 | func (c *Client) DecentrilizedFinanceDEFI() (*global.Defi, error) { 25 | rUrl := fmt.Sprintf("%s/decentralized_finance_defi", c.getGlobalURL()) 26 | resp, err := c.MakeReq(rUrl) 27 | if err != nil { 28 | return nil, err 29 | } 30 | 31 | var data *global.Defi 32 | err = json.Unmarshal([]byte(resp), &data) 33 | if err != nil { 34 | return nil, err 35 | } 36 | return data, nil 37 | } 38 | -------------------------------------------------------------------------------- /test/simple_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestSimplePrice(t *testing.T) { 10 | cgClient := goingecko.NewClient(nil, "") 11 | 12 | r, _ := cgClient.SimplePrice("bitcoin,ethereum", "btc,eth", true, true, true, true) 13 | if r == nil { 14 | t.Errorf("Error") 15 | } 16 | 17 | } 18 | 19 | func TestSimpleTokenPrice(t *testing.T) { 20 | cgClient := goingecko.NewClient(nil, "") 21 | 22 | r, _ := cgClient.SimpleTokenPrice("ethereum", "0x0D8775F648430679A709E98d2b0Cb6250d2887EF", "btc,eth", true, true, true, true) 23 | if r == nil { 24 | t.Errorf("Error") 25 | } 26 | 27 | } 28 | 29 | func TestSimpleSupportedVsCurrency(t *testing.T) { 30 | cgClient := goingecko.NewClient(nil, "") 31 | 32 | supVcurr, _ := cgClient.SimpleSupportedVsCurrency() 33 | if supVcurr == nil { 34 | t.Errorf("Error") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/nfts_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestNftsList(t *testing.T) { 9 | cgClient := goingecko.NewClient(nil, "") 10 | data, err := cgClient.NftsList("", "", 0, 0) 11 | if data == nil { 12 | t.Errorf("Error") 13 | } 14 | if err != nil { 15 | t.Errorf("Error: %s", err) 16 | } 17 | } 18 | 19 | func TestNftsId(t *testing.T) { 20 | cgClient := goingecko.NewClient(nil, "") 21 | data, err := cgClient.NftsId("squiggly") 22 | if data == nil { 23 | t.Errorf("Error") 24 | } 25 | if err != nil { 26 | t.Errorf("Error: %s", err) 27 | } 28 | } 29 | 30 | func TestNftsContract(t *testing.T) { 31 | cgClient := goingecko.NewClient(nil, "") 32 | data, err := cgClient.NftsContract("ethereum", "0x36F379400DE6c6BCDF4408B282F8b685c56adc60") 33 | if data == nil { 34 | t.Errorf("Error") 35 | } 36 | if err != nil { 37 | t.Errorf("Error: %s", err) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /coins/history.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type History struct { 6 | ID string `json:"id"` 7 | Symbol string `json:"symbol"` 8 | Name string `json:"name"` 9 | Localization types.Localization `json:"localization"` 10 | Image types.Image `json:"image"` 11 | MarketData HistoryMarketData `json:"market_data"` 12 | CommunityData types.CommunityData `json:"community_data"` 13 | DeveloperData types.DeveloperData `json:"developer_data"` 14 | PublicInterestStats types.PublicInterestStats `json:"public_interest_stats"` 15 | } 16 | 17 | type HistoryMarketData struct { 18 | CurrentPrice types.PriceRates `json:"current_price"` 19 | MarketCap types.PriceRates `json:"market_cap"` 20 | TotalVolume types.PriceRates `json:"total_volume"` 21 | } 22 | -------------------------------------------------------------------------------- /global/global.go: -------------------------------------------------------------------------------- 1 | package global 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type Global struct { 6 | Data data `json:"data"` 7 | } 8 | 9 | type data struct { 10 | ActiveCryptocurrencies int32 `json:"active_cryptocurrencies"` 11 | UpcomingIcos int32 `json:"upcoming_icos"` 12 | OngoingIcos int32 `json:"ongoing_icos"` 13 | EndedIcos int32 `json:"ended_icos"` 14 | Markets int32 `json:"markets"` 15 | TotalMarketCap types.PriceRates `json:"total_market_cap"` 16 | TotalVolume types.PriceRates `json:"total_volume"` 17 | MarketCapPercentage map[string]float64 `json:"market_cap_percentage"` 18 | MarketCapChangePercentage24hUsd float64 `json:"market_cap_change_percentage_24h_usd"` 19 | UpdatedAt float64 `json:"updated_at"` 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-present Julián Toledano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /test/derivatives_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestDerivatives(t *testing.T) { 9 | cgClient := goingecko.NewClient(nil, "") 10 | data, err := cgClient.Derivatives() 11 | if data == nil { 12 | t.Errorf("Error") 13 | } 14 | if err != nil { 15 | t.Errorf("Error: %s", err) 16 | } 17 | } 18 | 19 | func TestDerivativesExchanges(t *testing.T) { 20 | cgClient := goingecko.NewClient(nil, "") 21 | data, err := cgClient.DerivativesExchanges("", 0, 0) 22 | if data == nil { 23 | t.Errorf("Error") 24 | } 25 | if err != nil { 26 | t.Errorf("Error: %s", err) 27 | } 28 | } 29 | 30 | func TestDerivativesExchangesId(t *testing.T) { 31 | cgClient := goingecko.NewClient(nil, "") 32 | data, err := cgClient.DerivativesExchangesId("binance_futures", "all") 33 | if data == nil { 34 | t.Errorf("Error") 35 | } 36 | if err != nil { 37 | t.Errorf("Error: %s", err) 38 | } 39 | } 40 | 41 | func TestDerivativesExchangesList(t *testing.T) { 42 | cgClient := goingecko.NewClient(nil, "") 43 | data, err := cgClient.DerivativesExchangesList() 44 | if data == nil { 45 | t.Errorf("Error") 46 | } 47 | if err != nil { 48 | t.Errorf("Error: %s", err) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/contract_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestContractInfo(t *testing.T) { 10 | coin := "ethereum" 11 | contract := "0x0D8775F648430679A709E98d2b0Cb6250d2887EF" 12 | 13 | cgClient := goingecko.NewClient(nil, "") 14 | 15 | contractData, err := cgClient.ContractInfo(coin, contract) 16 | if err != nil { 17 | t.Errorf("Error: %v", err) 18 | } else if contractData.ID != "basic-attention-token" { 19 | t.Errorf("Id: %s", contractData.ID) 20 | } 21 | 22 | } 23 | 24 | func TestContractMarketChart(t *testing.T) { 25 | coin := "ethereum" 26 | contract := "0x0D8775F648430679A709E98d2b0Cb6250d2887EF" 27 | 28 | cgClient := goingecko.NewClient(nil, "") 29 | 30 | contractData, err := cgClient.ContractMarketChart(coin, contract, "usd", "10") 31 | if err != nil { 32 | t.Errorf("Error: %v", err) 33 | } 34 | if contractData == nil { 35 | t.Errorf("Error nil") 36 | } 37 | } 38 | 39 | func TestContractMarketChartRange(t *testing.T) { 40 | coin := "ethereum" 41 | contract := "0x0D8775F648430679A709E98d2b0Cb6250d2887EF" 42 | 43 | cgClient := goingecko.NewClient(nil, "") 44 | 45 | contractData, err := cgClient.ContractMarketChartRange(coin, contract, "usd", "1392500000", "1422577232") 46 | if err != nil { 47 | t.Errorf("Error: %v", err) 48 | } 49 | if contractData == nil { 50 | t.Errorf("Error nil") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /categories.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/categories" 9 | ) 10 | 11 | // CategoriesList List all categories 12 | // Cache / Update Frequency: every 5 minutes 13 | func (c *Client) CategoriesList() (*categories.CategoriesList, error) { 14 | rUrl := fmt.Sprintf("%s/%s", c.getCategoriesURL(), "list") 15 | resp, err := c.MakeReq(rUrl) 16 | if err != nil { 17 | return nil, err 18 | } 19 | var data *categories.CategoriesList 20 | err = json.Unmarshal(resp, &data) 21 | if err != nil { 22 | return nil, err 23 | } 24 | return data, nil 25 | } 26 | 27 | // Categories List all categories with market data 28 | // Cache / Update Frequency: every 5 minutes 29 | // Parameters: 30 | // 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 31 | func (c *Client) Categories(order string) (*categories.CategoriesWithMarketDataList, error) { 32 | params := url.Values{} 33 | 34 | if order != "" { 35 | params.Add("order", order) 36 | } 37 | 38 | rUrl := fmt.Sprintf("%s?%s", c.getCategoriesURL(), params.Encode()) 39 | resp, err := c.MakeReq(rUrl) 40 | if err != nil { 41 | return nil, err 42 | } 43 | var data *categories.CategoriesWithMarketDataList 44 | err = json.Unmarshal(resp, &data) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return data, nil 49 | } 50 | -------------------------------------------------------------------------------- /test/exchanges_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/JulianToledano/goingecko" 5 | "testing" 6 | ) 7 | 8 | func TestExchanges(t *testing.T) { 9 | 10 | cgClient := goingecko.NewClient(nil, "") 11 | 12 | data, err := cgClient.Exchanges("", "") 13 | if data == nil { 14 | t.Errorf("Error") 15 | } 16 | if err != nil { 17 | t.Errorf("Error: %s", err) 18 | } 19 | } 20 | 21 | func TestExchangesList(t *testing.T) { 22 | cgClient := goingecko.NewClient(nil, "") 23 | data, err := cgClient.ExchangesList() 24 | if data == nil { 25 | t.Errorf("Error") 26 | } 27 | if err != nil { 28 | t.Errorf("Error: %s", err) 29 | } 30 | } 31 | 32 | func TestExchangesId(t *testing.T) { 33 | cgClient := goingecko.NewClient(nil, "") 34 | data, err := cgClient.ExchangesId("sushiswap") 35 | if data == nil { 36 | t.Errorf("Error") 37 | } 38 | if err != nil { 39 | t.Errorf("Error: %s", err) 40 | } 41 | } 42 | 43 | func TestExchangesIdTickers(t *testing.T) { 44 | cgClient := goingecko.NewClient(nil, "") 45 | data, err := cgClient.ExchangesIdTickers("sushiswap", "", "", 0, "", "") 46 | if data == nil { 47 | t.Errorf("Error") 48 | } 49 | if err != nil { 50 | t.Errorf("Error: %s", err) 51 | } 52 | } 53 | 54 | func TestExchangesIdVolumeChart(t *testing.T) { 55 | cgClient := goingecko.NewClient(nil, "") 56 | data, err := cgClient.ExchangesIdVolumeChart("sushiswap", "1") 57 | if data == nil { 58 | t.Errorf("Error") 59 | } 60 | if err != nil { 61 | t.Errorf("Error: %s", err) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /coins/statusUpdates.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type StatusUpdates struct { 6 | StatusUpdates []Status `json:"status_updates"` 7 | } 8 | 9 | type Status struct { 10 | Description string `json:"description"` 11 | Category string `json:"category"` 12 | CreatedAt string `json:"created_at"` 13 | User string `json:"user"` 14 | UserTitle string `json:"user_title"` 15 | Pin bool `json:"pin"` 16 | Project Project `json:"project"` 17 | } 18 | 19 | type Project struct { 20 | Type string `json:"type"` 21 | ID string `json:"id"` 22 | Name string `json:"name"` 23 | Symbol string `json:"symbol"` 24 | Image types.Image `json:"image"` 25 | } 26 | 27 | /* 28 | { 29 | description: "Another big milestone for Fuse 🎉\r\n\r\nMajor crypto exchange MEXC Global has integrated the Fuse RPC and enabled FUSE deposits and withdrawals natively on the Fuse Network blockchain 😎\r\n\r\nRead more 👉 https://bit.ly/3rOopN4", 30 | category: "general", 31 | created_at: "2022-02-15T11:07:39.610Z", 32 | user: "Robert Miller", 33 | user_title: "Marcom Director ", 34 | pin: false, 35 | project: { 36 | type: "Coin", 37 | id: "fuse-network-token", 38 | name: "Fuse", 39 | symbol: "fuse", 40 | image: { 41 | thumb: "https://assets.coingecko.com/coins/images/10347/thumb/vUXKHEe.png?1601523640", 42 | small: "https://assets.coingecko.com/coins/images/10347/small/vUXKHEe.png?1601523640", 43 | large: "https://assets.coingecko.com/coins/images/10347/large/vUXKHEe.png?1601523640" 44 | } 45 | } 46 | } 47 | */ 48 | -------------------------------------------------------------------------------- /endpoints.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import "fmt" 4 | 5 | var ( 6 | version = "v3" 7 | BaseURL = fmt.Sprintf("https://api.coingecko.com/api/%s", version) 8 | ProBaseURL = fmt.Sprintf("https://pro-api.coingecko.com/api/%s", version) 9 | ) 10 | 11 | func (c *Client) getPingURL() string { 12 | return fmt.Sprintf("%s/ping", c.baseUrl) 13 | } 14 | 15 | func (c *Client) getSimpleURL() string { 16 | return fmt.Sprintf("%s/simple", c.baseUrl) 17 | } 18 | 19 | func (c *Client) getCoinsURL() string { 20 | return fmt.Sprintf("%s/coins", c.baseUrl) 21 | } 22 | 23 | func (c *Client) getAssetPlatformsURL() string { 24 | return fmt.Sprintf("%s/asset_platforms", c.baseUrl) 25 | } 26 | 27 | func (c *Client) getCategoriesURL() string { 28 | return fmt.Sprintf("%s/categories", c.getCoinsURL()) 29 | } 30 | 31 | func (c *Client) getExchangesURL() string { 32 | return fmt.Sprintf("%s/exchanges", c.baseUrl) 33 | } 34 | 35 | func (c *Client) getDerivativesURL() string { 36 | return fmt.Sprintf("%s/derivatives", c.baseUrl) 37 | } 38 | 39 | func (c *Client) getNftsURL() string { 40 | return fmt.Sprintf("%s/nfts", c.baseUrl) 41 | } 42 | 43 | func (c *Client) getSearchURL() string { 44 | return fmt.Sprintf("%s/search", c.baseUrl) 45 | } 46 | 47 | func (c *Client) getContractURL() string { 48 | return fmt.Sprintf("%s/coins", c.baseUrl) 49 | } 50 | 51 | func (c *Client) getExchangeRatesURL() string { 52 | return fmt.Sprintf("%s/exchange_rates", c.baseUrl) 53 | } 54 | 55 | func (c *Client) getTrendingURL() string { 56 | return fmt.Sprintf("%s/search/trending", c.baseUrl) 57 | } 58 | 59 | func (c *Client) getGlobalURL() string { 60 | return fmt.Sprintf("%s/global", c.baseUrl) 61 | } 62 | 63 | func (c *Client) getCompaniesURL() string { 64 | return fmt.Sprintf("%s/companies", c.baseUrl) 65 | } 66 | -------------------------------------------------------------------------------- /contract.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/contract" 9 | "github.com/JulianToledano/goingecko/types" 10 | ) 11 | 12 | func (c *Client) ContractInfo(id, contractAddress string) (*contract.ContractAddressInfo, error) { 13 | rUrl := fmt.Sprintf("%s/%s/%s/%s", c.getContractURL(), id, "contract", contractAddress) 14 | resp, err := c.MakeReq(rUrl) 15 | if err != nil { 16 | return nil, err 17 | } 18 | 19 | var data *contract.ContractAddressInfo 20 | err = json.Unmarshal([]byte(resp), &data) 21 | if err != nil { 22 | return nil, err 23 | } 24 | return data, nil 25 | } 26 | 27 | func (c *Client) ContractMarketChart(id, contractAddress, vsCurrency, days string) (*types.MarketChart, error) { 28 | params := url.Values{} 29 | params.Add("vs_currency", vsCurrency) 30 | params.Add("days", days) 31 | 32 | rUrl := fmt.Sprintf("%s/%s/%s/%s/%s?%s", c.getContractURL(), id, "contract", contractAddress, "market_chart", params.Encode()) 33 | resp, err := c.MakeReq(rUrl) 34 | if err != nil { 35 | return nil, err 36 | } 37 | 38 | var data *types.MarketChart 39 | err = json.Unmarshal([]byte(resp), &data) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return data, nil 44 | } 45 | 46 | func (c *Client) ContractMarketChartRange(id, contractAddress, vsCurrency, from, to string) (*types.MarketChart, error) { 47 | params := url.Values{} 48 | params.Add("vs_currency", vsCurrency) 49 | params.Add("from", from) 50 | params.Add("to", to) 51 | 52 | rUrl := fmt.Sprintf("%s/%s/%s/%s/%s?%s", c.getContractURL(), id, "contract", contractAddress, "market_chart/range", params.Encode()) 53 | resp, err := c.MakeReq(rUrl) 54 | if err != nil { 55 | return nil, err 56 | } 57 | 58 | var data *types.MarketChart 59 | err = json.Unmarshal([]byte(resp), &data) 60 | if err != nil { 61 | return nil, err 62 | } 63 | return data, nil 64 | } 65 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io" 7 | "net/http" 8 | 9 | "github.com/JulianToledano/goingecko/ping" 10 | ) 11 | 12 | const apiHeader = "x-cg-demo-api-key" 13 | const proApiHeader = "x-cg-pro-api-key" 14 | 15 | type Client struct { 16 | httpClient *http.Client 17 | baseUrl string 18 | apiKey string 19 | apiHeader string 20 | } 21 | 22 | func NewClient(httpClient *http.Client, apiKey string, isPro ...bool) *Client { 23 | if httpClient == nil { 24 | httpClient = http.DefaultClient 25 | } 26 | 27 | if isPro != nil { 28 | return &Client{ 29 | httpClient: httpClient, 30 | baseUrl: ProBaseURL, 31 | apiKey: apiKey, 32 | apiHeader: proApiHeader, 33 | } 34 | } 35 | 36 | return &Client{ 37 | httpClient: httpClient, 38 | baseUrl: BaseURL, 39 | apiKey: apiKey, 40 | apiHeader: apiHeader, 41 | } 42 | } 43 | 44 | func (c *Client) Close() { 45 | c.httpClient.CloseIdleConnections() 46 | } 47 | 48 | func doReq(req *http.Request, client *http.Client) ([]byte, error) { 49 | resp, err := client.Do(req) 50 | if err != nil { 51 | return nil, err 52 | } 53 | defer resp.Body.Close() 54 | body, err := io.ReadAll(resp.Body) 55 | if err != nil { 56 | return nil, err 57 | } 58 | if http.StatusOK != resp.StatusCode { 59 | return nil, fmt.Errorf("%s", body) 60 | } 61 | return body, nil 62 | } 63 | 64 | // MakeReq HTTP request helper 65 | func (c *Client) MakeReq(url string) ([]byte, error) { 66 | req, err := http.NewRequest("GET", url, nil) 67 | 68 | if c.apiKey != "" { 69 | req.Header.Add(c.apiHeader, c.apiKey) 70 | } 71 | 72 | if err != nil { 73 | return nil, err 74 | } 75 | resp, err := doReq(req, c.httpClient) 76 | if err != nil { 77 | return nil, err 78 | } 79 | return resp, err 80 | } 81 | 82 | // Ping /ping endpoint 83 | func (c *Client) Ping() (*ping.Ping, error) { 84 | resp, err := c.MakeReq(fmt.Sprintf("%s/ping", c.baseUrl)) 85 | if err != nil { 86 | return nil, err 87 | } 88 | var data *ping.Ping 89 | err = json.Unmarshal(resp, &data) 90 | if err != nil { 91 | return nil, err 92 | } 93 | return data, nil 94 | } 95 | -------------------------------------------------------------------------------- /exchangeRates/exchangeRates.go: -------------------------------------------------------------------------------- 1 | package exchangeRates 2 | 3 | type Rates struct { 4 | Rates coinRates `json:"rates"` 5 | } 6 | 7 | type rateInfo struct { 8 | Name string `json:"name"` 9 | Unit string `json:"unit"` 10 | Value float64 `json:"value"` 11 | Type string `json:"type"` 12 | } 13 | 14 | type coinRates struct { 15 | Btc rateInfo `json:"btc"` 16 | Eth rateInfo `json:"eth"` 17 | Ltc rateInfo `json:"ltc"` 18 | Bch rateInfo `json:"bch"` 19 | Bnb rateInfo `json:"bnb"` 20 | Eos rateInfo `json:"eos"` 21 | Xrp rateInfo `json:"xrp"` 22 | Xlm rateInfo `json:"xlm"` 23 | Link rateInfo `json:"link"` 24 | Dot rateInfo `json:"dot"` 25 | Yfi rateInfo `json:"yfi"` 26 | Usd rateInfo `json:"usd"` 27 | Aed rateInfo `json:"aed"` 28 | Ars rateInfo `json:"ars"` 29 | Aud rateInfo `json:"aud"` 30 | Bdt rateInfo `json:"bdt"` 31 | Bhd rateInfo `json:"bhd"` 32 | Bmd rateInfo `json:"bmd"` 33 | Brl rateInfo `json:"brl"` 34 | Cad rateInfo `json:"cad"` 35 | Chf rateInfo `json:"chf"` 36 | Clp rateInfo `json:"clp"` 37 | Cny rateInfo `json:"cny"` 38 | Czk rateInfo `json:"czk"` 39 | Dkk rateInfo `json:"dkk"` 40 | Eur rateInfo `json:"eur"` 41 | Gbp rateInfo `json:"gbp"` 42 | Hkd rateInfo `json:"hkd"` 43 | Huf rateInfo `json:"huf"` 44 | Idr rateInfo `json:"idr"` 45 | Ils rateInfo `json:"ils"` 46 | Inr rateInfo `json:"inr"` 47 | Jpy rateInfo `json:"jpy"` 48 | Krw rateInfo `json:"krw"` 49 | Kwd rateInfo `json:"kwd"` 50 | Lkr rateInfo `json:"lkr"` 51 | Mmk rateInfo `json:"mmk"` 52 | Mxn rateInfo `json:"mxn"` 53 | Myr rateInfo `json:"myr"` 54 | Ngn rateInfo `json:"ngn"` 55 | Nok rateInfo `json:"nok"` 56 | Nzd rateInfo `json:"nzd"` 57 | Php rateInfo `json:"php"` 58 | Pkr rateInfo `json:"pkr"` 59 | Pln rateInfo `json:"pln"` 60 | Rub rateInfo `json:"rub"` 61 | Sar rateInfo `json:"sar"` 62 | Sek rateInfo `json:"sek"` 63 | Sgd rateInfo `json:"sgd"` 64 | Thb rateInfo `json:"thb"` 65 | Try rateInfo `json:"try"` 66 | Twd rateInfo `json:"twd"` 67 | Uah rateInfo `json:"uah"` 68 | Vef rateInfo `json:"vef"` 69 | Vnd rateInfo `json:"vnd"` 70 | Zar rateInfo `json:"zar"` 71 | Xdr rateInfo `json:"xdr"` 72 | Xag rateInfo `json:"xag"` 73 | Xau rateInfo `json:"xau"` 74 | Bits rateInfo `json:"bits"` 75 | Sats rateInfo `json:"sats"` 76 | } 77 | -------------------------------------------------------------------------------- /coins/id.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type CoinID struct { 6 | ID string `json:"id"` 7 | Symbol string `json:"symbol"` 8 | Name string `json:"name"` 9 | AssetPlatformID string `json:"asset_platform_id"` 10 | BlockTimeInMinutes int `json:"block_time_in_minutes"` 11 | HashingAlgorithm string `json:"hashing_algorithm"` 12 | Categories []string `json:"categories"` 13 | // PublicNotice ¿? `json:"public_notice"` 14 | // AdditionalNotices ¿? `json:"public_notices"` 15 | Localization types.Localization `json:"localization"` 16 | Description types.Description `json:"description"` 17 | Links types.Links `json:"links"` 18 | Image types.Image `json:"image"` 19 | CountryOrigin string `json:"country_origin"` 20 | GenesisData string `json:"genesis_date"` 21 | SentimentVotesUpPercent float32 `json:"sentiment_votes_up_percentage"` 22 | SentimentVotesDownPercent float32 `json:"sentiment_votes_down_percentage"` 23 | MarketCapRank int `json:"market_cap_rank"` 24 | CoingeckoRank int `json:"coingecko_rank"` 25 | CoingeckoScore float32 `json:"coingecko_score"` 26 | DeveloperScore float32 `json:"developer_score"` 27 | CommunityScore float32 `json:"community_score"` 28 | LiquidityScore float32 `json:"liquidity_score"` 29 | PublicInterestScore float32 `json:"public_interest_score"` 30 | MarketData types.MarketData `json:"market_data"` 31 | CommunityData types.CommunityData `json:"community_data"` 32 | DeveloperData types.DeveloperData `json:"developer_data"` 33 | PublicInterestStats types.PublicInterestStats `json:"public_interest_stats"` 34 | Tickers []types.Ticker `json:"tickers"` 35 | } 36 | 37 | type ReposUrl struct { 38 | Github []string `json:"github"` 39 | Bitbucket []string `json:"bitbucket"` 40 | } 41 | -------------------------------------------------------------------------------- /simple.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | "github.com/JulianToledano/goingecko/simple" 10 | ) 11 | 12 | func (c *Client) SimplePrice(ids, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.Price, error) { 13 | params := url.Values{} 14 | 15 | params.Add("ids", ids) 16 | params.Add("vs_currencies", vsCurrencies) 17 | params.Add("include_market_cap", strconv.FormatBool(includeMarketCap)) 18 | params.Add("include_24hr_vol", strconv.FormatBool(includeDayVolume)) 19 | params.Add("include_24hr_change", strconv.FormatBool(includeDayChange)) 20 | params.Add("include_last_updated_at", strconv.FormatBool(includeLastTimeUpdated)) 21 | 22 | rUrl := fmt.Sprintf("%s/%s?%s", c.getSimpleURL(), "price", params.Encode()) 23 | resp, err := c.MakeReq(rUrl) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | var data simple.Price 29 | err = json.Unmarshal([]byte(resp), &data) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return data, nil 34 | } 35 | 36 | func (c *Client) SimpleTokenPrice(id, contractAddresses, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.TokenPrice, error) { 37 | params := url.Values{} 38 | 39 | params.Add("contract_addresses", contractAddresses) 40 | params.Add("vs_currencies", vsCurrencies) 41 | params.Add("include_market_cap", strconv.FormatBool(includeMarketCap)) 42 | params.Add("include_24hr_vol", strconv.FormatBool(includeDayVolume)) 43 | params.Add("include_24hr_change", strconv.FormatBool(includeDayChange)) 44 | params.Add("include_last_updated_at", strconv.FormatBool(includeLastTimeUpdated)) 45 | 46 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getSimpleURL(), "token_price", id, params.Encode()) 47 | resp, err := c.MakeReq(rUrl) 48 | if err != nil { 49 | return nil, err 50 | } 51 | 52 | var data simple.TokenPrice 53 | err = json.Unmarshal([]byte(resp), &data) 54 | if err != nil { 55 | return nil, err 56 | } 57 | return data, nil 58 | } 59 | 60 | func (c *Client) SimpleSupportedVsCurrency() (*simple.SupportedVsCurrency, error) { 61 | rUrl := fmt.Sprintf("%s/%s", c.getSimpleURL(), "supported_vs_currencies") 62 | resp, err := c.MakeReq(rUrl) 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | var data *simple.SupportedVsCurrency 68 | err = json.Unmarshal(resp, &data) 69 | if err != nil { 70 | return nil, err 71 | } 72 | return data, nil 73 | } 74 | -------------------------------------------------------------------------------- /nfts.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/nfts" 9 | ) 10 | 11 | // NftsList Use this to obtain all the NFT ids in order to make API calls, paginated to 100 items. 12 | // 13 | // Cache / Update Frequency: every 5 minutes 14 | // Parameters: 15 | // 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 16 | // assetPlatformId(string) - The id of the platform issuing tokens (See asset_platforms endpoint for list of options) 17 | // per_page(integer) - Valid values: 1..250. Total results per page 18 | // page(integer) - Page through results 19 | func (c *Client) NftsList(order, assetPlatformId string, perPage, page int32) ([]nfts.Nft, error) { 20 | params := url.Values{} 21 | if order != "" { 22 | params.Add("order", order) 23 | } 24 | if assetPlatformId != "" { 25 | params.Add("asset_platform_id", assetPlatformId) 26 | } 27 | if perPage > 0 { 28 | params.Add("per_page", string(perPage)) 29 | } 30 | if page > 0 { 31 | params.Add("page", string(page)) 32 | } 33 | 34 | rUrl := fmt.Sprintf("%s/list?%s", c.getNftsURL(), params.Encode()) 35 | resp, err := c.MakeReq(rUrl) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | var data []nfts.Nft 41 | err = json.Unmarshal(resp, &data) 42 | if err != nil { 43 | return nil, err 44 | } 45 | 46 | return data, nil 47 | } 48 | 49 | // NftsId Get current data (name, price_floor, volume_24h ...) for an NFT collection. native_currency (string) is only a representative of the currency. 50 | // 51 | // Cache / Update Frequency: every 60 seconds 52 | // Parameters: 53 | // id*(string) - id of nft collection (can be obtained from /nfts/list) 54 | func (c *Client) NftsId(id string) (*nfts.NftId, error) { 55 | rUrl := fmt.Sprintf("%s/%s", c.getNftsURL(), id) 56 | resp, err := c.MakeReq(rUrl) 57 | if err != nil { 58 | return nil, err 59 | } 60 | 61 | var data *nfts.NftId 62 | err = json.Unmarshal(resp, &data) 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | return data, nil 68 | } 69 | 70 | // NftsContract 71 | func (c *Client) NftsContract(assetPlatform, contract string) (*nfts.NftId, error) { 72 | rUrl := fmt.Sprintf("%s/%s/contract/%s", c.getNftsURL(), assetPlatform, contract) 73 | resp, err := c.MakeReq(rUrl) 74 | if err != nil { 75 | return nil, err 76 | } 77 | 78 | var data *nfts.NftId 79 | err = json.Unmarshal(resp, &data) 80 | if err != nil { 81 | return nil, err 82 | } 83 | 84 | return data, nil 85 | } 86 | -------------------------------------------------------------------------------- /test/coins_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/JulianToledano/goingecko" 7 | ) 8 | 9 | func TestCoinsList(t *testing.T) { 10 | 11 | cgClient := goingecko.NewClient(nil, "") 12 | 13 | coinData, _ := cgClient.CoinsList() 14 | if coinData == nil { 15 | t.Errorf("Error") 16 | } 17 | } 18 | 19 | func TestCoinsMarket(t *testing.T) { 20 | 21 | cgClient := goingecko.NewClient(nil, "") 22 | ids := []string{ 23 | "bitcoin", 24 | "ethereum", 25 | } 26 | priceChange := make([]string, 0) 27 | 28 | priceChange = append(priceChange, "24h") 29 | coinData, _ := cgClient.CoinsMarket("usd", ids, "", "", "100", "1", true, priceChange) 30 | if coinData == nil { 31 | t.Errorf("Error") 32 | } 33 | } 34 | 35 | func TestCoinsIds(t *testing.T) { 36 | 37 | cgClient := goingecko.NewClient(nil, "") 38 | 39 | coinData, err := cgClient.CoinsId("bitcoin", true, true, true, true, true, true) 40 | if err != nil { 41 | t.Errorf("Error: %s", err) 42 | } 43 | if coinData == nil { 44 | t.Errorf("Error") 45 | } 46 | 47 | } 48 | 49 | func TestCoinsIdsTickers(t *testing.T) { 50 | 51 | cgClient := goingecko.NewClient(nil, "") 52 | 53 | coinData, err := cgClient.CoinsIdTickers("bitcoin", "", "", "", "", "") 54 | if coinData == nil { 55 | t.Errorf("Error") 56 | } 57 | if err != nil { 58 | t.Errorf("Error: %s", err) 59 | } 60 | } 61 | 62 | func TestCoinsIdsHistory(t *testing.T) { 63 | 64 | cgClient := goingecko.NewClient(nil, "") 65 | 66 | coinData, err := cgClient.CoinsIdHistory("bitcoin", "30-12-17", true) 67 | if coinData == nil { 68 | t.Errorf("Error") 69 | } 70 | if err != nil { 71 | t.Errorf("Error: %s", err) 72 | } 73 | } 74 | 75 | func TestCoinsIdsMarketChart(t *testing.T) { 76 | 77 | cgClient := goingecko.NewClient(nil, "") 78 | 79 | coinData, err := cgClient.CoinsIdMarketChart("bitcoin", "usd", "10") 80 | if coinData == nil { 81 | t.Errorf("Error") 82 | } 83 | if err != nil { 84 | t.Errorf("Error: %s", err) 85 | } 86 | } 87 | 88 | func TestCoinsIdsMarketChartRange(t *testing.T) { 89 | 90 | cgClient := goingecko.NewClient(nil, "") 91 | 92 | coinData, err := cgClient.CoinsIdMarketChartRange("bitcoin", "usd", "1392577232", "1422577232") 93 | if coinData == nil { 94 | t.Errorf("Error") 95 | } 96 | if err != nil { 97 | t.Errorf("Error: %s", err) 98 | } 99 | } 100 | 101 | func TestCoinsIdsOhlc(t *testing.T) { 102 | 103 | cgClient := goingecko.NewClient(nil, "") 104 | 105 | coinData, err := cgClient.CoinsOhlc("bitcoin", "usd", "7") 106 | if coinData == nil { 107 | t.Errorf("Error") 108 | } 109 | if err != nil { 110 | t.Errorf("Error: %s", err) 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /coins/markets.go: -------------------------------------------------------------------------------- 1 | package coins 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | type Market struct { 6 | ID string `json:"ID"` 7 | Symbol string `json:"symbol"` 8 | Name string `json:"name"` 9 | Image string `json:"image"` 10 | CurrentPrice float64 `json:"current_price"` 11 | MarketCap float64 `json:"market_cap"` 12 | MarkeCcapRank int32 `json:"market_cap_rank"` 13 | FullyDilutedValuation float64 `json:"fully_diluted_valuation"` 14 | TotalVolume float64 `json:"total_volume"` 15 | HighDay float64 `json:"high_24h"` 16 | LowDay float64 `json:"low_24h"` 17 | PriceChangeDay float64 `json:"price_change_24h"` 18 | PriceChangePercentageDay float64 `json:"price_change_percentage_24h"` 19 | MarketCapChangeDay float64 `json:"market_cap_change_24h"` 20 | MarketCapChangePercentageDay float64 `json:"market_cap_change_percentage_24h"` 21 | CirculatingSupply float64 `json:"circulating_supply"` 22 | TotalSupply float64 `json:"total_supply"` 23 | MaxSupply float64 `json:"max_supply"` 24 | Ath float64 `json:"ath"` 25 | AthChangePercentage float64 `json:"ath_change_percentage"` 26 | AthDate string `json:"ath_date"` 27 | Atl float64 `json:"atl"` 28 | AtlChangePercentage float64 `json:"atl_change_percentage"` 29 | AtlDate string `json:"atl_date"` 30 | Roi types.Roi `json:"roi"` 31 | LastUpdated string `json:"last_updated"` 32 | SparklineInWeek types.Sparkline `json:"sparkline_in_7d"` 33 | PriceChangePercentageTwoWeeksInCurrency float64 `json:"price_change_percentage_14d_in_currency"` 34 | PriceChangePercentageHourInCurrency float64 `json:"price_change_percentage_1h_in_currency"` 35 | PriceChangePercentageThreeMonthsInCurrency float64 `json:"price_change_percentage_200d_in_currency"` 36 | PriceChangePercentageDayInCurrency float64 `json:"price_change_percentage_24h_in_currency"` 37 | PriceChangePercentageMonthInCurrency float64 `json:"price_change_percentage_30d_in_currency"` 38 | PriceChangePercentageWeekInCurrency float64 `json:"price_change_percentage_7d_in_currency"` 39 | } 40 | -------------------------------------------------------------------------------- /derivatives/derivatives.go: -------------------------------------------------------------------------------- 1 | package derivatives 2 | 3 | type Derivative struct { 4 | Market string `json:"market"` 5 | Symbol string `json:"symbol"` 6 | IndexId string `json:"index_id"` 7 | Price string `json:"price"` 8 | PricePercentageChange24h float64 `json:"price_percentage_change_24h"` 9 | ContractType string `json:"contract_type"` 10 | Index float64 `json:"index"` 11 | Basis float64 `json:"basis"` 12 | Spread float64 `json:"spread"` 13 | FundingRate float64 `json:"funding_rate"` 14 | OpenInterest float64 `json:"open_interest"` 15 | Volume24h float64 `json:"volume_24h"` 16 | LastTradedAt int64 `json:"last_traded_at"` 17 | ExpiredAt int64 `json:"expired_at"` 18 | } 19 | 20 | type Exchange struct { 21 | Name string `json:"name"` 22 | ID string `json:"id"` 23 | OpenInterestBtc float64 `json:"open_interest_btc"` 24 | TradeVolume24hBtc string `json:"trade_volume_24h_btc"` 25 | NumberOfPerpetualPairs int32 `json:"number_of_perpetual_pairs"` 26 | NumberOfFuturesPairs int32 `json:"number_of_futures_pairs"` 27 | Image string `json:"image"` 28 | YearEstablished int32 `json:"year_established"` 29 | Country string `json:"country"` 30 | Description string `json:"description"` 31 | Url string `json:"url"` 32 | } 33 | 34 | type ExchangeId struct { 35 | Name string `json:"name"` 36 | OpenInterestBtc float64 `json:"open_interest_btc"` 37 | TradeVolume24hBtc string `json:"trade_volume_24h_btc"` 38 | NumberOfPerpetualPairs int64 `json:"number_of_perpetual_pairs"` 39 | NumberOfPuturesPairs int64 `json:"number_of_futures_pairs"` 40 | Image string `json:"image"` 41 | YearEstablished int32 `json:"year_established"` 42 | Country string `json:"country"` 43 | Description string `json:"description"` 44 | Url string `json:"url"` 45 | Tickers []Ticker `json:"tickers"` 46 | } 47 | 48 | type Ticker struct { 49 | Symbol string `json:"symbol"` 50 | Base string `json:"base"` 51 | Target string `json:"target"` 52 | TradeURL string `json:"trade_url"` 53 | ContractType string `json:"contract_type"` 54 | Last float64 `json:"last"` 55 | H24PercentageChange float64 `json:"h24_percentage_change"` 56 | Index float64 `json:"index"` 57 | IndexBasicPercentage float64 `json:"index_basic_percentage"` 58 | BidAskSpread float64 `json:"bid_ask_spread"` 59 | FundingRate float64 `json:"funding_rate"` 60 | OpenInterestUsd float64 `json:"open_interest_usd"` 61 | H24Volume float64 `json:"h24_volume"` 62 | ConvertedVolume Converted `json:"converted_volume"` 63 | ConvertedLast Converted `json:"converted_last"` 64 | LastTradedAt string `json:"last_traded_at"` 65 | ExpiredAt float64 `json:"expired_at"` 66 | } 67 | 68 | type Converted struct { 69 | Btc string `json:"btc"` 70 | Eth string `json:"eth"` 71 | Usd string `json:"usd"` 72 | } 73 | 74 | type DerivativesListItem struct { 75 | ID string `json:"id"` 76 | Name string `json:"name"` 77 | } 78 | -------------------------------------------------------------------------------- /nfts/nfts.go: -------------------------------------------------------------------------------- 1 | package nfts 2 | 3 | type Nft struct { 4 | Id string `json:"id"` 5 | ContractAddress string `json:"contract_address"` 6 | Name string `json:"name"` 7 | AssetPlatformId string `json:"asset_platform_id"` 8 | Symbol string `json:"symbol"` 9 | } 10 | 11 | type NftId struct { 12 | Id string `json:"id"` 13 | ContractAddress string `json:"contract_address"` 14 | AssetPlatformId string `json:"asset_platform_id"` 15 | Name string `json:"name"` 16 | Symbol string `json:"symbol"` 17 | Image Image `json:"image"` 18 | Description string `json:"description"` 19 | NativeCurrency string `json:"native_currency"` 20 | NativeCurrencySymbol string `json:"native_currency_symbol"` 21 | FloorPrice Price `json:"floor_price"` 22 | MarketCap Price `json:"market_cap"` 23 | Volume24H Price `json:"volume_24h"` 24 | FloorPriceInUsd24HPercentageChange float64 `json:"floor_price_in_usd_24h_percentage_change"` 25 | FloorPrice24HPercentageChange Price `json:"floor_price_24h_percentage_change"` 26 | MarketCap24HPercentageChange Price `json:"market_cap_24h_percentage_change"` 27 | Volume24HPercentageChange Price `json:"volume_24h_percentage_change"` 28 | NumberOfUniqueAddresses float64 `json:"number_of_unique_addresses"` 29 | NumberOfUniqueAddresses24HPercentageChange float64 `json:"number_of_unique_addresses_24h_percentage_change"` 30 | VolumeInUsd24HPercentageChange float64 `json:"volume_in_usd_24h_percentage_change"` 31 | TotalSupply float64 `json:"total_supply"` 32 | OneDaySales float64 `json:"one_day_sales"` 33 | OneDaySales24HPercentageChange float64 `json:"one_day_sales_24h_percentage_change"` 34 | OneDayAverageSalePrice float64 `json:"one_day_average_sale_price"` 35 | OneDayAverageSalePrice24HPercentageChange float64 `json:"one_day_average_sale_price_24h_percentage_change"` 36 | Links Links `json:"links"` 37 | FloorPrice7DPercentageChange Price `json:"floor_price_7d_percentage_change"` 38 | FloorPrice14DPercentageChange Price `json:"floor_price_14d_percentage_change"` 39 | FloorPrice30DPercentageChange Price `json:"floor_price_30d_percentage_change"` 40 | FloorPrice60DPercentageChange Price `json:"floor_price_60d_percentage_change"` 41 | FloorPrice1YPercentageChange Price `json:"floor_price_1y_percentage_change"` 42 | Explorers []Explorers `json:"explorers"` 43 | } 44 | 45 | type Price struct { 46 | Usd float64 `json:"usd"` 47 | NativeCurrency float64 `json:"native_currency"` 48 | } 49 | 50 | type Image struct { 51 | Small string `json:"small"` 52 | } 53 | 54 | type Links struct { 55 | Homepage string `json:"homepage"` 56 | Twitter string `json:"twitter"` 57 | Discord string `json:"discord"` 58 | } 59 | 60 | type Explorers struct { 61 | Name string `json:"name"` 62 | Link string `json:"link"` 63 | } 64 | -------------------------------------------------------------------------------- /derivatives.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | 8 | "github.com/JulianToledano/goingecko/derivatives" 9 | ) 10 | 11 | // Derivatives List all derivative tickers. 12 | // Note: 'open_interest' and 'volume_24h' data are in USD 13 | // Cache / Update Frequency: every 30 seconds 14 | func (c *Client) Derivatives() ([]derivatives.Derivative, error) { 15 | 16 | rUrl := fmt.Sprintf("%s", c.getDerivativesURL()) 17 | resp, err := c.MakeReq(rUrl) 18 | if err != nil { 19 | return nil, err 20 | } 21 | 22 | var data []derivatives.Derivative 23 | err = json.Unmarshal(resp, &data) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return data, nil 29 | } 30 | 31 | // DerivativesExchanges List all derivative exchanges. 32 | // 33 | // Cache / Update Frequency: every 60 seconds 34 | // Parameters: 35 | // 36 | // order(string) - order results using following params name_asc,name_desc,open_interest_btc_asc, 37 | // open_interest_btc_desc,trade_volume_24h_btc_asc,trade_volume_24h_btc_desc 38 | // 39 | // perPage(integer) - Total results per page 40 | // page(integer) - Page through results 41 | func (c *Client) DerivativesExchanges(order string, perPage, page int32) ([]derivatives.Exchange, error) { 42 | params := url.Values{} 43 | if order != "" { 44 | params.Add("order", order) 45 | } 46 | if perPage > 0 { 47 | params.Add("per_page", string(perPage)) 48 | } 49 | if page > 0 { 50 | params.Add("page", string(page)) 51 | } 52 | 53 | rUrl := fmt.Sprintf("%s/exchanges?%s", c.getDerivativesURL(), params.Encode()) 54 | resp, err := c.MakeReq(rUrl) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | var data []derivatives.Exchange 60 | err = json.Unmarshal(resp, &data) 61 | if err != nil { 62 | return nil, err 63 | } 64 | 65 | return data, nil 66 | } 67 | 68 | // DerivativesExchangesId show derivative exchange data 69 | // 70 | // Dictionary: 71 | // 72 | // last: latest unconverted price in the respective pair target currency 73 | // volume: unconverted 24h trading volume in the respective pair target currency 74 | // converted_last: latest converted price in BTC, ETH, and USD 75 | // converted_volume: converted 24h trading volume in BTC, ETH, and USD 76 | // 77 | // Cache / Update Frequency: every 30 seconds 78 | // Parameters: 79 | // 80 | // id*(string) - pass the exchange id (can be obtained from derivatives/exchanges/list) eg. bitmex 81 | // includeTickers(string) - ['all', 'unexpired'] - expired to show unexpired tickers, all to list all tickers, 82 | // leave blank to omit tickers data in response 83 | func (c *Client) DerivativesExchangesId(id, includeTickers string) (*derivatives.ExchangeId, error) { 84 | params := url.Values{} 85 | if includeTickers != "" { 86 | params.Add("include_tickers", includeTickers) 87 | } 88 | 89 | rUrl := fmt.Sprintf("%s/exchanges/%s?%s", c.getDerivativesURL(), id, params.Encode()) 90 | resp, err := c.MakeReq(rUrl) 91 | if err != nil { 92 | return nil, err 93 | } 94 | 95 | var data *derivatives.ExchangeId 96 | err = json.Unmarshal(resp, &data) 97 | if err != nil { 98 | return nil, err 99 | } 100 | 101 | return data, nil 102 | } 103 | 104 | // DerivativesExchangesList List all derivative exchanges name and identifier. 105 | // 106 | // Cache / Update Frequency: every 5 minutes 107 | func (c *Client) DerivativesExchangesList() ([]derivatives.DerivativesListItem, error) { 108 | rUrl := fmt.Sprintf("%s/exchanges/list", c.getDerivativesURL()) 109 | resp, err := c.MakeReq(rUrl) 110 | if err != nil { 111 | return nil, err 112 | } 113 | 114 | var data []derivatives.DerivativesListItem 115 | err = json.Unmarshal(resp, &data) 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | return data, nil 121 | } 122 | -------------------------------------------------------------------------------- /exchanges/exchanges.go: -------------------------------------------------------------------------------- 1 | package exchanges 2 | 3 | type Exchange struct { 4 | ID string `json:"id"` 5 | Name string `json:"name"` 6 | YearEstablished int32 `json:"year_established"` 7 | Country string `json:"country"` 8 | Description string `json:"description"` 9 | Url string `json:"url"` 10 | Image string `json:"image"` 11 | HasTradingIncentive bool `json:"has_trading_incentive"` 12 | TrustScore int32 `json:"trust_score"` 13 | TrustScoreRank int32 `json:"trust_score_rank"` 14 | TradeVolume24h float64 `json:"trade_volume_24h_btc"` 15 | TradeVolume24jBtcNormalice float64 `json:"trade_volume_24h_btc_normalized"` 16 | } 17 | 18 | type ExchangesList []Exchange 19 | 20 | type ExchangeId struct { 21 | ID string `json:"id"` 22 | Name string `json:"name"` 23 | } 24 | 25 | type ExchangeWithTicker struct { 26 | Name string `json:"name"` 27 | YearEstablished int32 `json:"year_established"` 28 | Country string `json:"country"` 29 | Description string `json:"description"` 30 | Url string `json:"url"` 31 | Image string `json:"image"` 32 | FacebookUrl string `json:"facebook_url"` 33 | RedditYrl string `json:"reddit_url"` 34 | TelegramUrl string `json:"telegram_url"` 35 | SlackUrl string `json:"slack_url"` 36 | OtherUrl1 string `json:"other_url_1"` 37 | OtherUrl2 string `json:"other_url_2"` 38 | TwitterHandle string `json:"twitter_handle"` 39 | HasTradingIncentive bool `json:"has_trading_incentive"` 40 | Centralized bool `json:"centralized"` 41 | PublicNotice string `json:"public_notice"` 42 | AlertNotice string `json:"alert_notice"` 43 | TrustScore int32 `json:"trust_score"` 44 | TrustScoreRank int32 `json:"trust_score_rank"` 45 | TradeVolume24hBtc float64 `json:"trade_volume_24h_btc"` 46 | TradeVolume24hBtcNormalized float64 `json:"trade_volume_24h_btc_normalized"` 47 | Tickers []Ticker `json:"tickers"` 48 | StatusUpdates []StatusUpdates `json:"status_updates"` 49 | } 50 | 51 | type Tickers struct { 52 | Name string `json:"name"` 53 | Tickers []Ticker `json:"tickers"` 54 | } 55 | 56 | type Ticker struct { 57 | Base string `json:"base"` 58 | Target string `json:"target"` 59 | Market Market `json:"Market"` 60 | Last float64 `json:"Last"` 61 | Volume float64 `json:"volume"` 62 | ConvertedLast Converted `json:"converted_last"` 63 | ConvertedVolume Converted `json:"converted_volume"` 64 | TrustScore string `json:"trust_score"` 65 | BidAskSpreadPercentage float64 `json:"bid_ask_spread_percentage"` 66 | Timestamp string `json:"timestamp"` 67 | LastTradedAt string `json:"last_traded_at"` 68 | LastFetchAt string `json:"last_fetch_at"` 69 | IsAnomaly bool `json:"is_anomaly"` 70 | IsStale bool `json:"is_stale"` 71 | TradeUrl string `json:"trade_url"` 72 | TokenInfoUrl string `json:"token_info_url"` 73 | CoinID string `json:"coin_id"` 74 | TargetCoinID string `json:"target_coin_id"` 75 | } 76 | 77 | type StatusUpdates struct { 78 | // ?? 79 | } 80 | 81 | type Market struct { 82 | Name string `json:"name"` 83 | Identifier string `json:"identifier"` 84 | HasTradingIncentive bool `json:"has_trading_incentive"` 85 | } 86 | 87 | type Converted struct { 88 | Btc float64 `json:"btc"` 89 | Eth float64 `json:"eth"` 90 | Usd float64 `json:"usd"` 91 | } 92 | 93 | var VolumeChartValidDays = map[string]struct{}{ 94 | "1": {}, 95 | "7": {}, 96 | "14": {}, 97 | "30": {}, 98 | "90": {}, 99 | "180": {}, 100 | "365": {}, 101 | } 102 | 103 | type Volume []interface{} 104 | -------------------------------------------------------------------------------- /contract/contractAddress.go: -------------------------------------------------------------------------------- 1 | package contract 2 | 3 | import "github.com/JulianToledano/goingecko/types" 4 | 5 | // TODO: missing a lot of info 6 | type ContractAddressInfo struct { 7 | ID string `json:"id"` 8 | Symbol string `json:"symbol"` 9 | Name string `json:"name"` 10 | AssetPlatformId string `json:"asset_platform_id"` 11 | Platforms map[string]string `json:"platforms"` 12 | BlockTimeInMinutes int `json:"block_time_in_minutes"` 13 | Hashing_algorithm string `json:"hashing_algorithm"` 14 | Categories []string `json:"categories"` 15 | // public_notice `json:"//`" 16 | // additional_notices [] `json:"//`" 17 | Localization types.Localization `json:"localization"` 18 | Jescription types.Description `json:"description"` 19 | Links types.Links `json:"links"` 20 | Image types.Image `json:"image"` 21 | CountryOrigin string `json:"country_origin"` 22 | GenesisDate string `json:"genesis_date"` 23 | Contract_address string `json:"contract_address"` 24 | Sentiment_votes_up_percentage float64 `json:"sentiment_votes_up_percentage"` 25 | Sentiment_votes_down_percentage float64 `json:"sentiment_votes_down_percentage"` 26 | IcoData IcoData `json:"ico_data"` 27 | MarketCapRank int32 `json:"market_cap_rank"` 28 | CoingeckoRank int32 `json:"coingecko_rank"` 29 | CoingeckoScore float64 `json:"coingecko_score"` 30 | DeveloperScore float64 `json:"developer_score"` 31 | CommunityScore float64 `json:"community_score"` 32 | LiquidityScore float64 `json:"liquidity_score"` 33 | PublicInterestScore float64 `json:"public_interest_score"` 34 | MarketData types.MarketData `json:"market_data"` 35 | CommunityData types.CommunityData `json:"community_data"` 36 | DeveloperData types.DeveloperData `json:"developer_data"` 37 | PublicInterestStats types.PublicInterestStats `json:"public_interest_stats"` 38 | StatusUpdates []string `json:"status_updates"` 39 | LastUpdated string `json:"last_updated"` 40 | Tickers []types.Ticker `json:"tickers"` 41 | } 42 | 43 | type IcoData struct { 44 | IcoStartDate string `json:"ico_start_date"` 45 | IcoEndDate string `json:"ico_end_date"` 46 | ShortDesc string `json:"short_desc"` 47 | Description string `json:"description"` 48 | Links Links `json:"Linkslinks"` 49 | SoftcapCurrency string `json:"softcap_currency"` 50 | HardcapCurrency string `json:"hardcap_currency"` 51 | TotalRaisedCurrency string `json:"total_raised_currency"` 52 | // softcap_amount `json:"nullsoftcap_amount"` 53 | // hardcap_amount `json:"nullhardcap_amount"` 54 | // total_raised `json:"nulltotal_raised"` 55 | QuotePreSaleCurrency string `json:"quote_pre_sale_currency"` 56 | // base_pre_sale_amount `json:"nullbase_pre_sale_amount"` 57 | // quote_pre_sale_amount `json:"nullquote_pre_sale_amount"` 58 | QuotePublicSaleCurrency string `json:"quote_public_sale_currency"` 59 | BasePublicSaleAmount float64 `json:"base_public_sale_amount"` 60 | QuotePublicSaleAmount float64 `json:"quote_public_sale_amount"` 61 | AcceptingCurrencies string `json:"accepting_currencies"` 62 | CountryOrigin string `json:"country_origin"` 63 | // pre_sale_start_date `json:"nullpre_sale_start_date"` 64 | // pre_sale_end_date `json:"nullpre_sale_end_date"` 65 | // bounty_detail_url 66 | // amount_for_sale 67 | KycRequired bool `json:"kyc_required"` 68 | // whitelist_available 69 | // pre_sale_available 70 | PreSaleEnded bool `json:"pre_sale_ended"` 71 | } 72 | 73 | type Links struct { 74 | Web string `json:"web"` 75 | Blog string `json:"blog"` 76 | Github string `json:"github"` 77 | Twitter string `json:"twitter"` 78 | Facebook string `json:"facebook"` 79 | Telegram string `json:"telegram"` 80 | Whitepaper string `json:"whitepaper"` 81 | } 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Goingecko 2 | 3 | Coingecko API client for golang. 4 | 5 |

6 | goingecko 7 |

8 | 9 | 10 | 11 | ## Endpoints 12 | | Endpoint | Status | Function | 13 | |------------------------------------------------------------|--|---------------------------| 14 | | /ping | ✓ | Ping | 15 | | /simple/price | ✓ | SimplePrice | 16 | | /simple/token_price/{id} | ✓ | SimpleTokenPrice | 17 | | /simple/supported_vs_currencies | ✓ | SimpleSupportedVsCurrency | 18 | | /coins/list | ✓ | CoinsList | 19 | | /coins/markets | ✓ | CoinsMarket | 20 | | /coins/{id} | ✓ | CoinsId | 21 | | /coins/{id}/tickers | ✓ | CoinsIdTickers | 22 | | /coins/{id}/history | ✓ | CoinsIdHistory | 23 | | /coins/{id}/market_chart | ✓ | CoinsIdMarketChart | 24 | | /coins/{id}/market_chart/range | ✓ | CoinsIdMarketChartRange | 25 | | /coins/{id}/ohlc | ✓ | CoinsOhlc | 26 | | /coins/{id}/contract/{contract_address} | ✓ | ContractInfo | 27 | | /coins/{id}/contract/{contract_address}/market_chart/ | ✓ | ContractMarketChart | 28 | | /coins/{id}/contract/{contract_address}/market_chart/range | ✓ | ContractMarketChartRange | 29 | | /asset_platforms | ✓ | AssetPlatforms | 30 | | /coins/categories/list | ✓ | CategoriesList | 31 | | /coins/categories/ | ✓ | Categories | 32 | | /exchanges | ✓ | Exchanges | 33 | | /exchanges/list | ✓ | ExchangesList | 34 | | /exchanges/{id} | ✓ | ExchangesId | 35 | | /exchanges/{id}/tickers | ✓ | ExchangesIdTickers | 36 | | /exchanges/{id}/volume_chart | ✓ | ExchangesIdVolumeChart | 37 | | /derivaties | ✓ | Derivatives | 38 | | /derivaties/exchanges | ✓ | DerivativesExchanges | 39 | | /derivaties/exchanges/{id} | ✓ | DerivativesExchangesId | 40 | | /derivaties/exchanges/list | ✓ | DerivativesExchangesList | 41 | | /nfts/list | ✓ | NftsList | 42 | | /nfts/{id} | ✓ | NftsId | 43 | | /nfts/{asset_platform_id}/contract/{contract_address} | ✓ | NftsContract | 44 | | /exchange_rates | ✓ | ExchangeRates | 45 | | /search | ✓ | Search | 46 | | /search/trending | ✓ | Trending | 47 | | /global | ✓ | Global | 48 | | /global/decentralized_finance_defi | ✓ | DecentrilizedFinanceDEFI | 49 | | /companies/public_treasury/{coin_id} | ✓ | PublicTreasuryCoinId | 50 | 51 | ## Usage 52 | 53 | ```golang 54 | package main 55 | 56 | import ( 57 | "fmt" 58 | 59 | "github.com/JulianToledano/goingecko" 60 | ) 61 | 62 | func main() { 63 | cgClient := goingecko.NewClient(nil, "") 64 | defer cgClient.Close() 65 | 66 | data, err := cgClient.CoinsId("bitcoin", true, true, true, false, false, false) 67 | if err != nil { 68 | fmt.Print("Somethig went wrong...") 69 | return 70 | } 71 | fmt.Printf("Bitcoin price is: %f$", data.MarketData.CurrentPrice.Usd) 72 | } 73 | 74 | ``` 75 | Check dir [examples](examples) for more. 76 | 77 | ## Thanks 78 | This repo is based somehow in [superoo7/go-gecko](https://github.com/superoo7/go-gecko) work. 79 | 80 | Image was created with [Gophers](https://github.com/egonelbre/gophers) -------------------------------------------------------------------------------- /coins.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | "strings" 9 | 10 | "github.com/JulianToledano/goingecko/coins" 11 | "github.com/JulianToledano/goingecko/types" 12 | ) 13 | 14 | func (c *Client) CoinsList() ([]*coins.CoinInfo, error) { 15 | rUrl := fmt.Sprintf("%s/%s", c.getCoinsURL(), "list") 16 | resp, err := c.MakeReq(rUrl) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | var data []*coins.CoinInfo 22 | err = json.Unmarshal([]byte(resp), &data) 23 | if err != nil { 24 | return nil, err 25 | } 26 | return data, nil 27 | } 28 | 29 | func (c *Client) CoinsMarket(currency string, ids []string, category string, order string, perPage, page string, sparkline bool, priceChange []string) ([]*coins.Market, error) { 30 | params := url.Values{} 31 | idsParam := strings.Join(ids[:], ",") 32 | pChange := strings.Join(priceChange[:], ",") 33 | // vsCurrenciesParam := strings.Join(vsCurrencies[:], ",") 34 | 35 | params.Add("vs_currency", currency) 36 | params.Add("ids", idsParam) 37 | if category != "" { 38 | params.Add("category", category) 39 | } 40 | params.Add("order", order) 41 | params.Add("per_page", perPage) 42 | params.Add("page", page) 43 | params.Add("sparkline", strconv.FormatBool(sparkline)) 44 | params.Add("price_change_percentage", pChange) 45 | 46 | rUrl := fmt.Sprintf("%s/%s?%s", c.getCoinsURL(), "markets", params.Encode()) 47 | resp, err := c.MakeReq(rUrl) 48 | if err != nil { 49 | return nil, err 50 | } 51 | 52 | var data []*coins.Market 53 | err = json.Unmarshal([]byte(resp), &data) 54 | if err != nil { 55 | return nil, err 56 | } 57 | return data, nil 58 | } 59 | 60 | func (c *Client) CoinsId(id string, localization, tickers, marketData, communityData, developerData, sparkline bool) (*coins.CoinID, error) { 61 | params := url.Values{} 62 | 63 | params.Add("localization", strconv.FormatBool(localization)) 64 | params.Add("tickers", strconv.FormatBool(tickers)) 65 | params.Add("market_data", strconv.FormatBool(marketData)) 66 | params.Add("community_data", strconv.FormatBool(communityData)) 67 | params.Add("developer_data", strconv.FormatBool(developerData)) 68 | params.Add("sparkline", strconv.FormatBool(sparkline)) 69 | 70 | rUrl := fmt.Sprintf("%s/%s?%s", c.getCoinsURL(), id, params.Encode()) 71 | resp, err := c.MakeReq(rUrl) 72 | if err != nil { 73 | return nil, err 74 | } 75 | var data *coins.CoinID 76 | err = json.Unmarshal(resp, &data) 77 | if err != nil { 78 | return nil, err 79 | } 80 | return data, nil 81 | } 82 | 83 | func (c *Client) CoinsIdTickers(id, exchangeId, includeExchangeLogo, page, order, depth string) (*coins.Tickers, error) { 84 | params := url.Values{} 85 | 86 | params.Add("exchange_ids", exchangeId) 87 | params.Add("include_exchange_logo", includeExchangeLogo) 88 | params.Add("page", page) 89 | params.Add("order", order) 90 | params.Add("depth", depth) 91 | 92 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getCoinsURL(), id, "tickers", params.Encode()) 93 | resp, err := c.MakeReq(rUrl) 94 | if err != nil { 95 | return nil, err 96 | } 97 | var data *coins.Tickers 98 | err = json.Unmarshal(resp, &data) 99 | if err != nil { 100 | return nil, err 101 | } 102 | return data, nil 103 | } 104 | 105 | func (c *Client) CoinsIdHistory(id, date string, localization bool) (*coins.History, error) { 106 | params := url.Values{} 107 | 108 | params.Add("date", date) 109 | params.Add("localization", strconv.FormatBool(localization)) 110 | 111 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getCoinsURL(), id, "history", params.Encode()) 112 | resp, err := c.MakeReq(rUrl) 113 | if err != nil { 114 | return nil, err 115 | } 116 | var data *coins.History 117 | err = json.Unmarshal(resp, &data) 118 | if err != nil { 119 | return nil, err 120 | } 121 | return data, nil 122 | } 123 | 124 | func (c *Client) CoinsIdMarketChart(id, currency, days string) (*types.MarketChart, error) { 125 | params := url.Values{} 126 | params.Add("vs_currency", currency) 127 | params.Add("days", days) 128 | params.Add("interval", "daily") 129 | 130 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getCoinsURL(), id, "market_chart", params.Encode()) 131 | resp, err := c.MakeReq(rUrl) 132 | if err != nil { 133 | return nil, err 134 | } 135 | var data *types.MarketChart 136 | err = json.Unmarshal(resp, &data) 137 | if err != nil { 138 | return nil, err 139 | } 140 | return data, nil 141 | } 142 | 143 | func (c *Client) CoinsIdMarketChartRange(id, currency, from, to string) (*types.MarketChart, error) { 144 | params := url.Values{} 145 | params.Add("vs_currency", currency) 146 | params.Add("from", from) 147 | params.Add("to", to) 148 | 149 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getCoinsURL(), id, "market_chart/range", params.Encode()) 150 | resp, err := c.MakeReq(rUrl) 151 | if err != nil { 152 | return nil, err 153 | } 154 | var data *types.MarketChart 155 | err = json.Unmarshal(resp, &data) 156 | if err != nil { 157 | return nil, err 158 | } 159 | return data, nil 160 | } 161 | 162 | func (c *Client) CoinsOhlc(id, currency, days string) (*coins.Ohlc, error) { 163 | params := url.Values{} 164 | params.Add("vs_currency", currency) 165 | params.Add("days", days) 166 | 167 | rUrl := fmt.Sprintf("%s/%s/%s?%s", c.getCoinsURL(), id, "ohlc", params.Encode()) 168 | resp, err := c.MakeReq(rUrl) 169 | if err != nil { 170 | return nil, err 171 | } 172 | var data *coins.Ohlc 173 | err = json.Unmarshal(resp, &data) 174 | if err != nil { 175 | return nil, err 176 | } 177 | return data, nil 178 | } 179 | -------------------------------------------------------------------------------- /exchanges.go: -------------------------------------------------------------------------------- 1 | package goingecko 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net/url" 8 | 9 | "github.com/JulianToledano/goingecko/exchanges" 10 | ) 11 | 12 | // Exchanges List all exchanges 13 | // Cache / Update Frequency: every 60 seconds 14 | // Parameters 15 | // per_page (string) Total results per page: 16 | // 17 | // Valid values: 1...250 18 | // Total results per page 19 | // Default value:: 100 20 | // 21 | // page (string) page through results 22 | func (c *Client) Exchanges(perPage, page string) (*exchanges.ExchangesList, error) { 23 | params := url.Values{} 24 | if perPage != "" { 25 | params.Add("per_page", perPage) 26 | } 27 | if page != "" { 28 | params.Add("page", page) 29 | } 30 | 31 | rUrl := fmt.Sprintf("%s?%s", c.getExchangesURL(), params.Encode()) 32 | resp, err := c.MakeReq(rUrl) 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | var data *exchanges.ExchangesList 38 | err = json.Unmarshal(resp, &data) 39 | if err != nil { 40 | return nil, err 41 | } 42 | 43 | return data, nil 44 | } 45 | 46 | // ExchangesList Use this to obtain all the markets' id in order to make API calls 47 | // Cache / Update Frequency: every 5 minutes 48 | func (c *Client) ExchangesList() ([]exchanges.ExchangeId, error) { 49 | rUrl := fmt.Sprintf("%s/list", c.getExchangesURL()) 50 | resp, err := c.MakeReq(rUrl) 51 | if err != nil { 52 | return nil, err 53 | } 54 | 55 | var data []exchanges.ExchangeId 56 | err = json.Unmarshal(resp, &data) 57 | if err != nil { 58 | return nil, err 59 | } 60 | 61 | return data, nil 62 | } 63 | 64 | // ExchangesId Get exchange volume in BTC and tickers. 65 | // For derivatives (e.g. bitmex, binance_futures), please use /derivatives/exchange/{id} endpoint. 66 | // 67 | // IMPORTANT: 68 | // Ticker object is limited to 100 items, to get more tickers, use /exchanges/{id}/tickers 69 | // Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for more than 8 hours. 70 | // Ticker is_anomaly is true if ticker's price is outliered by our system. 71 | // You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide) 72 | // 73 | // Dictionary: 74 | // 75 | // last: latest unconverted price in the respective pair target currency 76 | // volume: unconverted 24h trading volume in the respective pair target currency 77 | // converted_last: latest converted price in BTC, ETH, and USD 78 | // converted_volume: converted 24h trading volume in BTC, ETH, and USD 79 | // timestamp: returns the last time that the price has changed 80 | // last_traded_at: returns the last time that the price has changed 81 | // last_fetch_at: returns the last time we call the API 82 | // Cache / Update Frequency: every 60 seconds 83 | func (c *Client) ExchangesId(id string) (*exchanges.ExchangeWithTicker, error) { 84 | rUrl := fmt.Sprintf("%s/%s", c.getExchangesURL(), id) 85 | resp, err := c.MakeReq(rUrl) 86 | if err != nil { 87 | return nil, err 88 | } 89 | 90 | var data *exchanges.ExchangeWithTicker 91 | err = json.Unmarshal(resp, &data) 92 | if err != nil { 93 | return nil, err 94 | } 95 | 96 | return data, nil 97 | } 98 | 99 | // ExchangesIdTickers Get exchange tickers (paginated) 100 | // IMPORTANT: 101 | // Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for more than 8 hours. 102 | // Ticker is_anomaly is true if ticker's price is outliered by our system. 103 | // You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide) 104 | // 105 | // Dictionary: 106 | // 107 | // last: latest unconverted price in the respective pair target currency 108 | // volume: unconverted 24h trading volume in the respective pair target currency 109 | // converted_last: latest converted price in BTC, ETH, and USD 110 | // converted_volume: converted 24h trading volume in BTC, ETH, and USD 111 | // timestamp: returns the last time that the price has changed 112 | // last_traded_at: returns the last time that the price has changed 113 | // last_fetch_at: returns the last time we call the API 114 | // Cache / Update Frequency: every 60 seconds 115 | // Parameters: 116 | // 117 | // id* - string - pass the exchange id (can be obtained from /exchanges/list) eg. binance 118 | // coinIds - string - filter tickers by coin_ids (ref: v3/coins/list) 119 | // includeExchangeLogo - string - flag to show exchange_logo. valid values: true, false 120 | // page - integer - Page through results 121 | // 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 122 | // order - string - valid values: trust_score_desc (default), trust_score_asc and volume_desc 123 | func (c *Client) ExchangesIdTickers(id, coinIds, includeExchangeLogo string, page int32, depth, order string) (*exchanges.Tickers, error) { 124 | params := url.Values{} 125 | if coinIds != "" { 126 | params.Add("coin_ids", coinIds) 127 | } 128 | if includeExchangeLogo != "" { 129 | params.Add("include_exchange_logo", includeExchangeLogo) 130 | } 131 | if page > 0 { 132 | params.Add("page", string(page)) 133 | } 134 | if depth != "0" { 135 | params.Add("depth", depth) 136 | } 137 | if order != "0" { 138 | params.Add("order", order) 139 | } 140 | rUrl := fmt.Sprintf("%s/%s/tickers?%s", c.getExchangesURL(), id, params.Encode()) 141 | resp, err := c.MakeReq(rUrl) 142 | if err != nil { 143 | return nil, err 144 | } 145 | 146 | var data *exchanges.Tickers 147 | err = json.Unmarshal(resp, &data) 148 | if err != nil { 149 | return nil, err 150 | } 151 | 152 | return data, nil 153 | } 154 | 155 | // ExchangesIdVolumeChart Get 24 hour rolling trading volume data (in BTC) for a given exchange. 156 | // Data granularity is automatic (cannot be adjusted) 157 | // 158 | // 1 day = 10-minutely 159 | // 2-90 days = hourly 160 | // 91 days above = daily 161 | // 162 | // Note: exclusive endpoint is available for paid users to query more than 1 year of historical data 163 | // 164 | // Cache / Update Frequency: every 60 seconds 165 | // Parameters: 166 | // id* - string - pass the exchange id (can be obtained from /exchanges/list) eg. binance 167 | // days* - string - Data up to number of days ago (1/7/14/30/90/180/365) 168 | func (c *Client) ExchangesIdVolumeChart(id, days string) ([]exchanges.Volume, error) { 169 | if _, ok := exchanges.VolumeChartValidDays[days]; !ok { 170 | return nil, errors.New("not valid day") 171 | } 172 | 173 | params := url.Values{} 174 | params.Add("days", days) 175 | 176 | rUrl := fmt.Sprintf("%s/%s/volume_chart?%s", c.getExchangesURL(), id, params.Encode()) 177 | resp, err := c.MakeReq(rUrl) 178 | if err != nil { 179 | return nil, err 180 | } 181 | 182 | var data []exchanges.Volume 183 | err = json.Unmarshal(resp, &data) 184 | if err != nil { 185 | return nil, err 186 | } 187 | 188 | return data, nil 189 | } 190 | -------------------------------------------------------------------------------- /types/types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type Description struct { 4 | En string `json:"en"` 5 | De string `json:"de"` 6 | Es string `json:"es"` 7 | Fr string `json:"fr"` 8 | It string `json:"it"` 9 | Pl string `json:"pl"` 10 | Ro string `json:"ro"` 11 | Hu string `json:"hu"` 12 | Nl string `json:"nl"` 13 | Pt string `json:"pt"` 14 | Sv string `json:"sv"` 15 | Vi string `json:"vi"` 16 | Tr string `json:"tr"` 17 | Ru string `json:"ru"` 18 | Ja string `json:"ja"` 19 | Zh string `json:"zh"` 20 | Ko string `json:"ko"` 21 | Ar string `json:"ar"` 22 | Th string `json:"th"` 23 | ID string `json:"id"` 24 | Zhtw string `json:"zh-tw"` 25 | } 26 | 27 | type Links struct { 28 | Homepage []string `json:"homepage"` 29 | BlockchainSite []string `json:"blockchain_site"` 30 | OfficialForumURL []string `json:"official_forum_url"` 31 | ChatURL []string `json:"chat_url"` 32 | AnnouncementURL []string `json:"announcement_url"` 33 | TwitterScreenName string `json:"twitter_screen_name"` 34 | FacebookUsername string `json:"facebook_username"` 35 | BitcointalkThreadIdentifier float64 `json:"bitcointalk_thread_identifier"` 36 | TelegramChannelIdentifier string `json:"telegram_channel_identifier"` 37 | SubredditURL string `json:"subreddit_url"` 38 | ReposURL ReposUrl `json:"repos_url"` 39 | } 40 | 41 | type ReposUrl struct { 42 | Github []string `json:"github"` 43 | Bitbucket []string `json:"bitbucket"` 44 | } 45 | 46 | type Roi struct { 47 | Time float64 `json:"times"` 48 | Currency string `json:"currency"` 49 | Percentage float64 `json:"percentage"` 50 | } 51 | 52 | type Sparkline struct { 53 | Price []float64 `json:"price"` 54 | } 55 | 56 | type Ticker struct { 57 | Base string `json:"base"` 58 | Target string `json:"target"` 59 | Market MarketTicker `json:"market"` 60 | Last float64 `json:"last"` 61 | Volume float64 `json:"volume"` 62 | ConvertedLast Converted `json:"converted_last"` 63 | ConvertedVolume Converted `json:"converted_volume"` 64 | TrustScore string `json:"trust_score"` 65 | BidAskSpreadPercentage float64 `json:"bid_ask_spread_percentage"` 66 | Timestamp string `json:"timestamp"` 67 | LastTradedAt string `json:"last_traded_at"` 68 | LastFetchAt string `json:"last_fetch_at"` 69 | IsAnomaly bool `json:"is_anomaly"` 70 | IsStale bool `json:"is_stale"` 71 | TradeURL string `json:"trade_url"` 72 | // token_info_url `json:"token_info_url"` null 73 | CoinID string `json:"coin_id"` 74 | } 75 | 76 | type MarketTicker struct { 77 | Name string `json:"name"` 78 | Identifier string `json:"identifier"` 79 | HasTradingIncentive bool `json:"has_trading_incentive"` 80 | } 81 | 82 | type Converted struct { 83 | Btc float64 `json:"btc"` 84 | Eth float64 `json:"eth"` 85 | Usd float64 `json:"usd"` 86 | } 87 | 88 | type Image struct { 89 | Thumb string `json:"thumb"` 90 | Small string `json:"small"` 91 | Large string `json:"large"` 92 | } 93 | 94 | type Localization struct { 95 | En string `json:"en"` 96 | De string `json:"de"` 97 | Es string `json:"es"` 98 | Fr string `json:"fr"` 99 | It string `json:"it"` 100 | Pl string `json:"pl"` 101 | Ro string `json:"ro"` 102 | Hu string `json:"hu"` 103 | Nl string `json:"nl"` 104 | Pt string `json:"pt"` 105 | Sv string `json:"sv"` 106 | Vi string `json:"vi"` 107 | Tr string `json:"tr"` 108 | Ru string `json:"ru"` 109 | Ja string `json:"ja"` 110 | Zh string `json:"zh"` 111 | Zhw string `json:"zhw"` 112 | Ko string `json:"ko"` 113 | Ar string `json:"ar"` 114 | Th string `json:"th"` 115 | ID string `json:"id"` 116 | } 117 | 118 | type CommunityData struct { 119 | FacebookLikes float64 `json:"facebook_likes"` 120 | TwitterFollowers float64 `json:"twitter_followers"` 121 | RedditAveragePosts float64 `json:"reddit_average_posts_48h"` 122 | RedditAverageCommentsTwoDays float64 `json:"reddit_average_comments_48h"` 123 | RedditSubscribers float64 `json:"reddit_subscribers"` 124 | RedditAccountsActiveTwoDays float64 `json:"reddit_accounts_active_48h"` 125 | TelegramChannelUserCount float64 `json:"telegram_channel_user_count"` 126 | } 127 | 128 | type DeveloperData struct { 129 | Forks float32 `json:"forks"` 130 | Stars float32 `json:"stars"` 131 | Subscribers float32 `json:"subscribers"` 132 | TotalIssues float32 `json:"total_issues"` 133 | ClosedIssues float32 `json:"closed_issues"` 134 | PullRequestsMerged float32 `json:"pull_requests_merged"` 135 | PullRequestContributors float32 `json:"pull_request_contributors"` 136 | CodeAdditionsDeletionsMonth CodeStats `json:"code_additions_deletions_4_weeks"` 137 | CommitCountMonth float32 `json:"commit_count_4_weeks"` 138 | MonthCommitActivitySeries []float32 `json:"last_4_weeks_commit_activity_series"` 139 | } 140 | 141 | type CodeStats struct { 142 | Additions int16 `json:"additions"` 143 | Deletions int16 `json:"deletions"` 144 | } 145 | 146 | type PublicInterestStats struct { 147 | AlexaRank float64 `json:"alexa_rank"` 148 | // bing_matches `json:"bing_matches"` 149 | } 150 | 151 | type MarketData struct { 152 | CurrentPrice PriceRates `json:"current_price"` 153 | Roi Roi `json:"roi"` 154 | Ath PriceRates `json:"ath"` 155 | AthChangePercentage PriceRates `json:"ath_change_percentage"` 156 | AthDate DateRates `json:"ath_date"` 157 | Atl PriceRates `json:"atl"` 158 | AtlChangePercentage PriceRates `json:"atl_change_percentage"` 159 | AtlDate DateRates `json:"atl_date"` 160 | MarketCap PriceRates `json:"market_cap"` 161 | MarketCapRank int16 `json:"market_cap_rank"` 162 | FullyDilutedValuation PriceRates `json:"fully_diluted_valuation"` 163 | TotalVolume PriceRates `json:"total_volume"` 164 | High24 PriceRates `json:"high_24h"` 165 | Low24 PriceRates `json:"low_24h"` 166 | PriceChangeDay float64 `json:"price_change_24h"` 167 | PriceChangePercentDay float64 `json:"price_change_percentage_24h"` 168 | PriceChangePercentWeek float64 `json:"price_change_percentage_7d"` 169 | PriceChangePercentTwoWeeks float64 `json:"price_change_percentage_14d"` 170 | PriceChangePercentMonth float64 `json:"price_change_percentage_30d"` 171 | PriceChangePercentTwoMonths float64 `json:"price_change_percentage_60d"` 172 | PriceChangePercentHalfYear float64 `json:"price_change_percentage_200d"` 173 | PriceChangePercentYear float64 `json:"price_change_percentage_1y"` 174 | MarketCapChangeDay float64 `json:"market_cap_change_24h"` 175 | MarketCapChangePercentDay float64 `json:"market_cap_change_percentage_24h"` 176 | MarketCapChangeDayRates PriceRates `json:"price_change_24h_in_currency"` 177 | PriceChangePercentageHourCurrency PriceRates `json:"price_change_percentage_1h_in_currency"` 178 | PriceChangePercentageDayCurrency PriceRates `json:"price_change_percentage_24h_in_currency"` 179 | PriceChangePercentageWeekCurrency PriceRates `json:"price_change_percentage_7d_in_currency"` 180 | PriceChangePercentageTwoWeekCurrency PriceRates `json:"price_change_percentage_14d_in_currency"` 181 | PriceChangePercentageMonthCurrency PriceRates `json:"price_change_percentage_30d_in_currency"` 182 | PriceChangePercentageTwoMonthCurrency PriceRates `json:"price_change_percentage_60d_in_currency"` 183 | PriceChangePercentageHalfYearCurrency PriceRates `json:"price_change_percentage_200d_in_currency"` 184 | PriceChangePercentageYearCurrency PriceRates `json:"price_change_percentage_1y_in_currency"` 185 | MarketCapChangeDayCurrency PriceRates `json:"market_cap_change_24h_in_currency"` 186 | MarketCapChangePercentageDayCurrency PriceRates `json:"market_cap_change_percentage_24h_in_currency"` 187 | TotalSupply float64 `json:"total_supply"` 188 | MaxSupply float64 `json:"max_supply"` 189 | CirculatingSupply float64 `json:"circulating_supply"` 190 | Sparkline Sparkline `json:"sparkline_7d"` 191 | LastUpdated string `json:"last_updated"` 192 | } 193 | type PriceRates struct { 194 | Aed float64 `json:"aed"` 195 | Ars float64 `json:"ars"` 196 | Aud float64 `json:"aud"` 197 | Bch float64 `json:"bch"` 198 | Bdt float64 `json:"bdt"` 199 | Bhd float64 `json:"bhd"` 200 | Bmd float64 `json:"bmd"` 201 | Bnb float64 `json:"bnb"` 202 | Brl float64 `json:"brl"` 203 | Btc float64 `json:"btc"` 204 | Cad float64 `json:"cad"` 205 | Chf float64 `json:"chf"` 206 | Clp float64 `json:"clp"` 207 | Cny float64 `json:"cny"` 208 | Czk float64 `json:"czk"` 209 | Dkk float64 `json:"dkk"` 210 | Dot float64 `json:"dot"` 211 | Eos float64 `json:"eos"` 212 | Eth float64 `json:"eth"` 213 | Eur float64 `json:"eur"` 214 | Gbp float64 `json:"gbp"` 215 | Hkd float64 `json:"hkd"` 216 | Huf float64 `json:"huf"` 217 | Idr float64 `json:"idr"` 218 | Ils float64 `json:"ils"` 219 | Inr float64 `json:"inr"` 220 | Jpy float64 `json:"jpy"` 221 | Krw float64 `json:"krw"` 222 | Kwd float64 `json:"kwd"` 223 | Lkr float64 `json:"lkr"` 224 | Ltc float64 `json:"ltc"` 225 | Mmk float64 `json:"mmk"` 226 | Mxn float64 `json:"mxn"` 227 | Myr float64 `json:"myr"` 228 | Ngn float64 `json:"ngn"` 229 | Nok float64 `json:"nok"` 230 | Nzd float64 `json:"nzd"` 231 | Php float64 `json:"php"` 232 | Pkr float64 `json:"pkr"` 233 | Pln float64 `json:"pln"` 234 | Rub float64 `json:"rub"` 235 | Sar float64 `json:"sar"` 236 | Sek float64 `json:"sek"` 237 | Sgd float64 `json:"sgd"` 238 | Thb float64 `json:"thb"` 239 | Try float64 `json:"try"` 240 | Twd float64 `json:"twd"` 241 | Uah float64 `json:"uah"` 242 | Usd float64 `json:"usd"` 243 | Vef float64 `json:"vef"` 244 | Vnd float64 `json:"vnd"` 245 | Xag float64 `json:"xag"` 246 | Xau float64 `json:"xau"` 247 | Xdr float64 `json:"xdr"` 248 | Xlm float64 `json:"xlm"` 249 | Xrp float64 `json:"xrp"` 250 | Yfi float64 `json:"yfi"` 251 | Zar float64 `json:"zar"` 252 | Bits float64 `json:"bits"` 253 | Link float64 `json:"link"` 254 | Sats float64 `json:"sats"` 255 | } 256 | 257 | type DateRates struct { 258 | Aed string `json:"aed"` 259 | Ars string `json:"ars"` 260 | Aud string `json:"aud"` 261 | Bch string `json:"bch"` 262 | Bdt string `json:"bdt"` 263 | Bhd string `json:"bhd"` 264 | Bmd string `json:"bmd"` 265 | Bnb string `json:"bnb"` 266 | Brl string `json:"brl"` 267 | Btc string `json:"btc"` 268 | Cad string `json:"cad"` 269 | Chf string `json:"chf"` 270 | Clp string `json:"clp"` 271 | Cny string `json:"cny"` 272 | Czk string `json:"czk"` 273 | Dkk string `json:"dkk"` 274 | Dot string `json:"dot"` 275 | Eos string `json:"eos"` 276 | Eth string `json:"eth"` 277 | Eur string `json:"eur"` 278 | Gbp string `json:"gbp"` 279 | Hkd string `json:"hkd"` 280 | Huf string `json:"huf"` 281 | Idr string `json:"idr"` 282 | Ils string `json:"ils"` 283 | Inr string `json:"inr"` 284 | Jpy string `json:"jpy"` 285 | Krw string `json:"krw"` 286 | Kwd string `json:"kwd"` 287 | Lkr string `json:"lkr"` 288 | Ltc string `json:"ltc"` 289 | Mmk string `json:"mmk"` 290 | Mxn string `json:"mxn"` 291 | Myr string `json:"myr"` 292 | Ngn string `json:"ngn"` 293 | Nok string `json:"nok"` 294 | Nzd string `json:"nzd"` 295 | Php string `json:"php"` 296 | Pkr string `json:"pkr"` 297 | Pln string `json:"pln"` 298 | Rub string `json:"rub"` 299 | Sar string `json:"sar"` 300 | Sek string `json:"sek"` 301 | Sgd string `json:"sgd"` 302 | Thb string `json:"thb"` 303 | Try string `json:"try"` 304 | Twd string `json:"twd"` 305 | Uah string `json:"uah"` 306 | Usd string `json:"usd"` 307 | Vef string `json:"vef"` 308 | Vnd string `json:"vnd"` 309 | Xag string `json:"xag"` 310 | Xau string `json:"xau"` 311 | Xdr string `json:"xdr"` 312 | Xlm string `json:"xlm"` 313 | Xrp string `json:"xrp"` 314 | Yfi string `json:"yfi"` 315 | Zar string `json:"zar"` 316 | Bits string `json:"bits"` 317 | Link string `json:"link"` 318 | Sats string `json:"sats"` 319 | } 320 | 321 | type CapRates struct { 322 | Aed int64 `json:"aed"` 323 | Ars int64 `json:"ars"` 324 | Aud int64 `json:"aud"` 325 | Bch int64 `json:"bch"` 326 | Bdt int64 `json:"bdt"` 327 | Bhd int64 `json:"bhd"` 328 | Bmd int64 `json:"bmd"` 329 | Bnb int64 `json:"bnb"` 330 | Brl int64 `json:"brl"` 331 | Btc int64 `json:"btc"` 332 | Cad int64 `json:"cad"` 333 | Chf int64 `json:"chf"` 334 | Clp int64 `json:"clp"` 335 | Cny int64 `json:"cny"` 336 | Czk int64 `json:"czk"` 337 | Dkk int64 `json:"dkk"` 338 | Dot int64 `json:"dot"` 339 | Eos int64 `json:"eos"` 340 | Eth int64 `json:"eth"` 341 | Eur int64 `json:"eur"` 342 | Gbp int64 `json:"gbp"` 343 | Hkd int64 `json:"hkd"` 344 | Huf int64 `json:"huf"` 345 | Idr int64 `json:"idr"` 346 | Ils int64 `json:"ils"` 347 | Inr int64 `json:"inr"` 348 | Jpy int64 `json:"jpy"` 349 | Krw int64 `json:"krw"` 350 | Kwd int64 `json:"kwd"` 351 | Lkr int64 `json:"lkr"` 352 | Ltc int64 `json:"ltc"` 353 | Mmk int64 `json:"mmk"` 354 | Mxn int64 `json:"mxn"` 355 | Myr int64 `json:"myr"` 356 | Ngn int64 `json:"ngn"` 357 | Nok int64 `json:"nok"` 358 | Nzd int64 `json:"nzd"` 359 | Php int64 `json:"php"` 360 | Pkr int64 `json:"pkr"` 361 | Pln int64 `json:"pln"` 362 | Rub int64 `json:"rub"` 363 | Sar int64 `json:"sar"` 364 | Sek int64 `json:"sek"` 365 | Sgd int64 `json:"sgd"` 366 | Thb int64 `json:"thb"` 367 | Try int64 `json:"try"` 368 | Twd int64 `json:"twd"` 369 | Uah int64 `json:"uah"` 370 | Usd int64 `json:"usd"` 371 | Vef int64 `json:"vef"` 372 | Vnd int64 `json:"vnd"` 373 | Xag int64 `json:"xag"` 374 | Xau int64 `json:"xau"` 375 | Xdr int64 `json:"xdr"` 376 | Xlm int64 `json:"xlm"` 377 | Xrp int64 `json:"xrp"` 378 | Yfi int64 `json:"yfi"` 379 | Zar int64 `json:"zar"` 380 | Bits int64 `json:"bits"` 381 | Link int64 `json:"link"` 382 | Sats int64 `json:"sats"` 383 | } 384 | --------------------------------------------------------------------------------