Created
February 21, 2022 02:48
-
-
Save dhruvio/f09a881c9a38981a533c6c9af9851727 to your computer and use it in GitHub Desktop.
A script to get cryptocurrency price data from CoinMarketCap.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Be sure to add your CoinMarketCap API key below. | |
function COINMARKETCAP(token) { | |
var requestOptions = { | |
method: 'GET', | |
qs: { | |
start: 1, | |
limit: 5000, | |
convert: 'USD' | |
}, | |
headers: { | |
'X-CMC_PRO_API_KEY': 'YOUR_API_KEY_HERE' | |
}, | |
json: true, | |
gzip: true | |
}; | |
var url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=' + token; | |
var result = UrlFetchApp.fetch(url, requestOptions); | |
var txt = result.getContentText(); | |
var d = JSON.parse(txt); | |
return d.data[token].quote.USD.price; | |
} | |
// Usage | |
// =COINMARKETCAP("BTC") | |
// =COINMARKETCAP("ZIL") | |
// =COINMARKETCAP("ADA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment