-
-
Save saibakatar/1f1efb3b4680ba6951433a5f4a820804 to your computer and use it in GitHub Desktop.
Configure Coinmarketcap API on Google sheets
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
function getCryptoPrice() { | |
var sh1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); | |
var sh2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2"); | |
//Make sure that you got the API key from Coinmarketcap API dashboard and paste it in sheet_1 on cell B1 | |
var apiKey=sh1.getRange(1, 2).getValue(); | |
var url="https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=BTC" | |
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); | |
sh2.getRange(1, 2).setValue(parseData.data.BTC.quote.USD.price) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment