Skip to content

Instantly share code, notes, and snippets.

@seanli1
Forked from erajanraja24/Coinmarketcap API
Last active March 13, 2021 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanli1/9e3d17e066300714a056a1db1db675d5 to your computer and use it in GitHub Desktop.
Save seanli1/9e3d17e066300714a056a1db1db675d5 to your computer and use it in GitHub Desktop.
Configure Coinmarketcap API on Google sheets
function crypto(coinSymbol) {
var apiKey = "YOUR-API-KEY-HERE";
var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=" + coinSymbol
var requestOptions = {
method: 'GET',
uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest',
qs: {
start: 1,
limit: 5000,
convert: 'USD'
},
headers: {
'X-CMC_PRO_API_KEY': apiKey
},
json: true,
gzip: true
};
var httpRequest = UrlFetchApp.fetch(url, requestOptions);
var getContext = httpRequest.getContentText();
var parseData = JSON.parse(getContext);
// Logger.log(parseData.data);
return parseData.data[coinSymbol].quote.USD.price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment