├── README.md ├── golang ├── README.md ├── api-tutorial-with-header.go ├── api-tutorial-with-header_test.go ├── api-tutorial.go ├── api-tutorial_test.go └── main.go ├── googlesheet └── README.md ├── javascript └── README.md ├── node ├── README.md ├── api-tutorial-with-header.js └── api-tutorial.js └── python ├── README.md ├── api-tutorial-pandas.py ├── api-tutorial-with-header.py └── api-tutorial.py /README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Tutorials 9 | Here you can find a few code examples written in different languages so you can quickly get started. 10 | 11 | * [Python tutorials](https://github.com/CryptoCompareLTD/api-guides/tree/master/python) 12 | * [Node tutorials](https://github.com/CryptoCompareLTD/api-guides/tree/master/node) 13 | * [Javascript (frontend) tutorials](https://github.com/CryptoCompareLTD/api-guides/tree/master/javascript) 14 | * [Google Sheets tutorials](https://github.com/CryptoCompareLTD/api-guides/tree/master/googlesheet) 15 | * [Golang tutorials](https://github.com/CryptoCompareLTD/api-guides/tree/master/golang) 16 | 17 | ## Rate limit 18 | You get the following error message if you are out of the rate limit: 19 | ``` 20 | { 21 | "Response": "Error", 22 | "Message": "You are over your rate limit please upgrade your account!", 23 | "HasWarning": false, 24 | "Type": 99, 25 | "RateLimit": { 26 | "calls_made": { 27 | "second": 53, 28 | "minute": 915, 29 | "hour": 63283, 30 | "day": 127321, 31 | "month": 6720577, 32 | "total_calls": 29374377 33 | }, 34 | "max_calls": { 35 | "second": 50, 36 | "minute": 2000, 37 | "hour": 100000, 38 | "day": 1500000, 39 | "month": 15000000 40 | } 41 | }, 42 | "Data": {} 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /golang/README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API with golang 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Get data from API 9 | There are many modules to do an http request, in this example we use the request npm module. 10 | 11 | ### Send API key in request header 12 | You can choose to send your authentication in the request header as in [api-tutorial-with-header.go](https://github.com/CryptoCompareLTD/api-guides/blob/master/golang/api-tutorial-with-header.go) or in the request parameters as in [api-tutorial.go](https://github.com/CryptoCompareLTD/api-guides/blob/master/golang/api-tutorial.go). 13 | -------------------------------------------------------------------------------- /golang/api-tutorial-with-header.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "net/http" 8 | ) 9 | 10 | func getPriceMultiFullWithHeader(fsyms, tsyms, apiKey string) error { 11 | 12 | url := apiEndpoint + "data/pricemultifull?fsyms=" + fsyms + "&tsyms=" + tsyms 13 | apiKeyHeader := "Apikey " + apiKey 14 | 15 | req, err := http.NewRequest("GET", url, nil) 16 | if err != nil { 17 | return fmt.Errorf("getPriceMultiFull, creating HTTP request, %s", err) 18 | } 19 | req.Header.Set("authorization", apiKeyHeader) 20 | 21 | client := &http.Client{} 22 | 23 | resp, err := client.Do(req) 24 | if err != nil { 25 | return fmt.Errorf("getPriceMultiFull, querying url, %s", err) 26 | } 27 | 28 | defer resp.Body.Close() 29 | 30 | body, err := ioutil.ReadAll(resp.Body) 31 | if err != nil { 32 | return fmt.Errorf("getPriceMultiFull, reading body %s", err) 33 | } 34 | 35 | var respObj interface{} 36 | if err := json.Unmarshal(body, &respObj); err != nil { 37 | return fmt.Errorf("getPriceMultiFull, unmarshalling response, %s", err) 38 | } 39 | 40 | fmt.Println(respObj) 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /golang/api-tutorial-with-header_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func TestGetPriceMultiFullWithHeader(t *testing.T) { 6 | if err := getPriceMultiFullWithHeader("BTC", "USD", ""); err != nil { 7 | t.Fatal(err) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /golang/api-tutorial.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "net/http" 8 | ) 9 | 10 | func getPriceMultiFull(fsyms, tsyms, apiKey string) error { 11 | 12 | url := apiEndpoint + "data/pricemultifull?fsyms=" + fsyms + "&tsyms=" + tsyms + "&apiKey=" + apiKey 13 | 14 | resp, err := http.Get(url) 15 | if err != nil { 16 | return fmt.Errorf("getPriceMultiFull, querying url, %s", err) 17 | } 18 | 19 | defer resp.Body.Close() 20 | 21 | body, err := ioutil.ReadAll(resp.Body) 22 | if err != nil { 23 | return fmt.Errorf("getPriceMultiFull, reading body %s", err) 24 | } 25 | 26 | var respObj interface{} 27 | if err := json.Unmarshal(body, &respObj); err != nil { 28 | return fmt.Errorf("getPriceMultiFull, unmarshalling response, %s", err) 29 | } 30 | 31 | fmt.Println(respObj) 32 | 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /golang/api-tutorial_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func TestGetPriceMultiFull(t *testing.T) { 6 | if err := getPriceMultiFull("BTC", "USD", ""); err != nil { 7 | t.Fatal(err) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /golang/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "log" 4 | 5 | var apiEndpoint = "https://min-api.cryptocompare.com/" 6 | 7 | func main() { 8 | 9 | fsyms := "BTC" 10 | tsyms := "USD" 11 | var apiKey string 12 | 13 | if err := getPriceMultiFull(fsyms, tsyms, apiKey); err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | if err := getPriceMultiFullWithHeader(fsyms, tsyms, apiKey); err != nil { 18 | log.Fatal(err) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /googlesheet/README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API in Google Sheets 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Create custom function to get data into Google Sheets using Google Apps Script 9 | [Here is a tutorial on how to use Google Apps Script](https://www.benlcollins.com/apps-script/beginner-apis/) 10 | 11 | ### Get price data 12 | [See example Google sheet.](https://docs.google.com/spreadsheets/d/1FgrLAZqVtYAa0-9nk4q2hYE3bIuxxQ7MdRmazrT1-tU/edit?usp=sharing) 13 | Paste the following code snippet into your script editor in Google Sheets. 14 | 15 | ``` 16 | function ccPrice(options) { 17 | var params = []; 18 | for (i in options){ 19 | params.push(options[i][0] + "=" + options[i][1]); 20 | } 21 | var url = "https://min-api.cryptocompare.com/data/price?" + params.join("&"); 22 | Logger.log(url); 23 | 24 | var response = UrlFetchApp.fetch(url); 25 | 26 | var data = response.getContentText(); 27 | var json = JSON.parse(data); 28 | var res = [] 29 | for (key in json) { 30 | res.push([key, json[key]]); 31 | } 32 | return res; 33 | } 34 | ``` 35 | You can now call ccPrice function in your sheet passing in the parameters necessary as in the example. 36 | 37 | ### Get history data 38 | [See example Google sheet.](https://docs.google.com/spreadsheets/d/1FgrLAZqVtYAa0-9nk4q2hYE3bIuxxQ7MdRmazrT1-tU/edit?usp=sharing) 39 | Paste the following code snippet into your script editor in Google Sheets. 40 | 41 | ``` 42 | function ccHistory(options) { 43 | var params = []; 44 | for (i in options){ 45 | params.push(options[i][0] + "=" + options[i][1]); 46 | } 47 | var url = "https://min-api.cryptocompare.com/data/histoday?" + params.join("&"); 48 | Logger.log(url); 49 | 50 | var response = UrlFetchApp.fetch(url); 51 | 52 | var data = response.getContentText(); 53 | var response = JSON.parse(data); 54 | if (response.Response == "Error") { 55 | return "API Error"; 56 | } 57 | var json = response.Data; 58 | var res = []; 59 | for (i in json) { 60 | if (i == 0) { 61 | var row = []; 62 | for (key in json[i]) { 63 | row.push(key); 64 | } 65 | res.push(row); 66 | } 67 | var row = []; 68 | for (key in json[i]) { 69 | row.push(json[i][key]); 70 | } 71 | res.push(row); 72 | } 73 | return res; 74 | } 75 | ``` 76 | -------------------------------------------------------------------------------- /javascript/README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API with frontend javascript 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Get data into browser 9 | There are many modules that you can use to call an API, here we are using [axios](https://www.npmjs.com/package/axios). 10 | Add the following cdn to your frontend code: 11 | ``` 12 | 13 | ``` 14 | 15 | ### Send request with API key in header 16 | ``` 17 | var getFullURL = function(url, options){ 18 | const params = []; 19 | for (let key in options) { 20 | params.push(`${key}=${options[key]}`); 21 | } 22 | return url + '?' + params.join("&"); 23 | } 24 | 25 | var apiKey = "SET-YOUR-API-KEY"; 26 | 27 | var baseUrl = "https://min-api.cryptocompare.com/data/price" 28 | 29 | var options = { 30 | fsym: "BTC", 31 | tsyms: "USD" 32 | }; 33 | 34 | var headers = { 35 | "Authorization": "Apikey " + apiKey 36 | }; 37 | 38 | var fullURL = getFullURL(baseURL, options); 39 | 40 | axios.get(fullURL, {headers: headers}) 41 | .then(function(response) { 42 | console.log(response.data); 43 | console.log(response.status); 44 | console.log(response.statusText); 45 | console.log(response.headers); 46 | console.log(response.config); 47 | }); 48 | 49 | ``` 50 | 51 | ### Send request with API key in payload 52 | ``` 53 | var getFullURL = function(url, options){ 54 | const params = []; 55 | for (let key in options) { 56 | params.push(`${key}=${options[key]}`); 57 | } 58 | return url + '?' + params.join("&"); 59 | } 60 | 61 | var apiKey = "SET-YOUR-API-KEY"; 62 | 63 | var baseUrl = "https://min-api.cryptocompare.com/data/price" 64 | 65 | var options = { 66 | api_key: apiKey; 67 | fsym: "BTC", 68 | tsyms: "USD" 69 | }; 70 | 71 | var fullURL = getFullURL(baseURL, options); 72 | 73 | axios.get(fullURL) 74 | .then(function(response) { 75 | console.log(response.data); 76 | console.log(response.status); 77 | console.log(response.statusText); 78 | console.log(response.headers); 79 | console.log(response.config); 80 | }); 81 | 82 | ``` 83 | 84 | -------------------------------------------------------------------------------- /node/README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API with node 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Get data from API 9 | There are many modules to do an http request, in this example we use the request npm module. 10 | 11 | ### Send API key in request header 12 | You can choose to send your authentication in the request header as in [this tutorial](https://github.com/CryptoCompareLTD/api-guides/blob/master/node/api-tutorial-with-header.js). 13 | 14 | ``` 15 | const request = require('request'); 16 | 17 | const apiKey = "SET-YOUR-API-KEY-HERE"; 18 | 19 | function getFullURL(url, options){ 20 | const params = []; 21 | for (let key in options) { 22 | params.push(`${key}=${options[key]}`); 23 | } 24 | return url + '?' + params.join("&"); 25 | } 26 | 27 | const baseURL = "https://min-api.cryptocompare.com/data/price"; 28 | 29 | const options = { 30 | fsym: "BTC", 31 | tsyms: "USD" 32 | }; 33 | 34 | const headers = { 35 | "Authorization": "Apikey " + apiKey 36 | }; 37 | 38 | const fullURL = getFullURL(baseURL, options); 39 | 40 | request.get({ 41 | url: fullURL, 42 | headers: headers 43 | }, function(err, res, body){ 44 | if (err){ 45 | console.log(err); 46 | } else { 47 | console.log(body); 48 | } 49 | }); 50 | ``` 51 | 52 | ### Send API key in request payload 53 | You can send the API key as a request payload as in [this tutorial](https://github.com/CryptoCompareLTD/api-guides/blob/master/node/api-tutorial.js). 54 | 55 | ``` 56 | const request = require('request'); 57 | 58 | const apiKey = "SET-YOUR-API-KEY-HERE"; 59 | 60 | function getFullURL(url, options){ 61 | const params = []; 62 | for (let key in options) { 63 | params.push(`${key}=${options[key]}`); 64 | } 65 | return url + '?' + params.join("&"); 66 | } 67 | 68 | const baseURL = "https://min-api.cryptocompare.com/data/price"; 69 | 70 | const options = { 71 | api_key: apiKey, 72 | fsym: "BTC", 73 | tsyms: "USD" 74 | }; 75 | 76 | const fullURL = getFullURL(baseURL, options); 77 | 78 | request.get(fullURL, function(err, res, body){ 79 | if (err){ 80 | console.log(err); 81 | } else { 82 | console.log(body); 83 | } 84 | }); 85 | ``` 86 | -------------------------------------------------------------------------------- /node/api-tutorial-with-header.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | 3 | const apiKey = "SET-YOUR-API-KEY-HERE"; 4 | 5 | function getFullURL(url, options){ 6 | const params = []; 7 | for (let key in options) { 8 | params.push(`${key}=${options[key]}`); 9 | } 10 | return url + '?' + params.join("&"); 11 | } 12 | 13 | const baseURL = "https://min-api.cryptocompare.com/data/price"; 14 | 15 | const options = { 16 | fsym: "BTC", 17 | tsyms: "USD" 18 | }; 19 | 20 | const headers = { 21 | "Authorization": "Apikey " + apiKey 22 | }; 23 | 24 | const fullURL = getFullURL(baseURL, options); 25 | 26 | request.get({ 27 | url: fullURL, 28 | headers: headers 29 | }, function(err, res, body){ 30 | if (err){ 31 | console.log(err); 32 | } else { 33 | console.log(body); 34 | } 35 | }); 36 | -------------------------------------------------------------------------------- /node/api-tutorial.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | 3 | const apiKey = "SET-YOUR-API-KEY-HERE"; 4 | 5 | function getFullURL(url, options){ 6 | const params = []; 7 | for (let key in options) { 8 | params.push(`${key}=${options[key]}`); 9 | } 10 | return url + '?' + params.join("&"); 11 | } 12 | 13 | const baseURL = "https://min-api.cryptocompare.com/data/price"; 14 | 15 | const options = { 16 | api_key: apiKey, 17 | fsym: "BTC", 18 | tsyms: "USD" 19 | }; 20 | 21 | const fullURL = getFullURL(baseURL, options); 22 | 23 | request.get(fullURL, function(err, res, body){ 24 | if (err){ 25 | console.log(err); 26 | } else { 27 | console.log(body); 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # How to use the CryptoCompare API with python 2 | 3 | Official documentation [here](https://min-api.cryptocompare.com/documentation). 4 | 5 | ## Generate an API key 6 | [Read this guide to generate an API key](https://www.cryptocompare.com/coins/guides/how-to-use-our-api/). 7 | 8 | ## Get data from API 9 | There are many python libraries to do an http request, in this example we use the requests library. 10 | 11 | ### Send API key in request header 12 | You can choose to send your authentication in the request header as in [this tutorial](https://github.com/CryptoCompareLTD/api-guides/blob/master/python/api-tutorial-with-header.py). 13 | 14 | ``` 15 | import requests 16 | 17 | apiKey = "SET-YOUR-API-KEY-HERE" 18 | 19 | url = "https://min-api.cryptocompare.com/data/price" 20 | 21 | payload = { 22 | "fsym": "BTC", 23 | "tsyms": "USD" 24 | } 25 | 26 | headers = { 27 | "authorization": "Apikey " + apiKey 28 | } 29 | 30 | result = requests.get(url, headers=headers, params=payload).json() 31 | 32 | print(result) 33 | """ 34 | Result: 35 | {u'USD': 4069.35} 36 | """ 37 | 38 | ``` 39 | 40 | ### Send API key in request payload 41 | You can send the API key as a request payload as in [this tutorial](https://github.com/CryptoCompareLTD/api-guides/blob/master/python/api-tutorial.py). 42 | 43 | ``` 44 | import requests 45 | 46 | apiKey = "SET-YOUR-API-KEY-HERE" 47 | 48 | url = "https://min-api.cryptocompare.com/data/price" 49 | 50 | payload = { 51 | "api_key": apiKey, 52 | "fsym": "BTC", 53 | "tsyms": "USD" 54 | } 55 | 56 | result = requests.get(url, params=payload).json() 57 | 58 | print(result) 59 | """ 60 | Result: 61 | {u'USD': 4069.35} 62 | """ 63 | ``` 64 | 65 | ### Load historical data into pandas dataframe 66 | Pandas is a popular tool among data scientists, [in this tutorial](https://github.com/CryptoCompareLTD/api-guides/blob/master/python/api-tutorial-pandas.py) we show an example how to load historical data into a dataframe. 67 | 68 | ``` 69 | import requests 70 | import pandas as pd 71 | 72 | apiKey = "SET-YOUR-API-KEY-HERE" 73 | 74 | url = "https://min-api.cryptocompare.com/data/histoday" 75 | 76 | payload = { 77 | "api_key": apiKey, 78 | "fsym": "BTC", 79 | "tsym": "USD", 80 | "limit": 100 81 | } 82 | 83 | result = requests.get(url, params=payload).json() 84 | 85 | df = pd.DataFrame(result['Data']) 86 | 87 | print(df.head()) 88 | 89 | """ 90 | close high low open time volumefrom volumeto 91 | 0 6594.98 6662.60 6510.54 6623.82 1538352000 38926.98 2.569599e+08 92 | 1 6525.47 6618.95 6478.04 6594.98 1538438400 40624.20 2.671663e+08 93 | 2 6492.26 6537.07 6428.98 6525.46 1538524800 47186.00 3.063853e+08 94 | 3 6579.79 6622.32 6486.86 6492.61 1538611200 42142.96 2.776140e+08 95 | 4 6632.87 6683.55 6546.98 6580.00 1538697600 39731.28 2.625623e+08 96 | 97 | """ 98 | ``` 99 | 100 | -------------------------------------------------------------------------------- /python/api-tutorial-pandas.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import pandas as pd 3 | 4 | apiKey = "SET-YOUR-API-KEY-HERE" 5 | 6 | url = "https://min-api.cryptocompare.com/data/histoday" 7 | 8 | payload = { 9 | "api_key": apiKey, 10 | "fsym": "BTC", 11 | "tsym": "USD", 12 | "limit": 100 13 | } 14 | 15 | result = requests.get(url, params=payload).json() 16 | 17 | df = pd.DataFrame(result['Data']) 18 | 19 | print(df.head()) 20 | 21 | """ 22 | close high low open time volumefrom volumeto 23 | 0 6594.98 6662.60 6510.54 6623.82 1538352000 38926.98 2.569599e+08 24 | 1 6525.47 6618.95 6478.04 6594.98 1538438400 40624.20 2.671663e+08 25 | 2 6492.26 6537.07 6428.98 6525.46 1538524800 47186.00 3.063853e+08 26 | 3 6579.79 6622.32 6486.86 6492.61 1538611200 42142.96 2.776140e+08 27 | 4 6632.87 6683.55 6546.98 6580.00 1538697600 39731.28 2.625623e+08 28 | 29 | """ 30 | -------------------------------------------------------------------------------- /python/api-tutorial-with-header.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | apiKey = "SET-YOUR-API-KEY-HERE" 4 | 5 | url = "https://min-api.cryptocompare.com/data/price" 6 | 7 | payload = { 8 | "fsym": "BTC", 9 | "tsyms": "USD" 10 | } 11 | 12 | headers = { 13 | "authorization": "Apikey " + apiKey 14 | } 15 | 16 | result = requests.get(url, headers=headers, params=payload).json() 17 | 18 | print(result) 19 | """ 20 | Result: 21 | {u'USD': 4069.35} 22 | """ 23 | 24 | -------------------------------------------------------------------------------- /python/api-tutorial.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | apiKey = "SET-YOUR-API-KEY-HERE" 4 | 5 | url = "https://min-api.cryptocompare.com/data/price" 6 | 7 | payload = { 8 | "api_key": apiKey, 9 | "fsym": "BTC", 10 | "tsyms": "USD" 11 | } 12 | 13 | result = requests.get(url, params=payload).json() 14 | 15 | print(result) 16 | """ 17 | Result: 18 | {u'USD': 4069.35} 19 | """ 20 | 21 | --------------------------------------------------------------------------------