-
-
Save seanli1/9e3d17e066300714a056a1db1db675d5 to your computer and use it in GitHub Desktop.
Configure Coinmarketcap API on Google sheets
This file contains hidden or 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
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