-
-
Save erajanraja24/117bf3de60970ff78d1671153d4eab73 to your computer and use it in GitHub Desktop.
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) | |
} |
Hello,
I have an error ode, can you help ?
thanks
Error
Exception: Request failed for https://pro-api.coinmarketcap.com returned code 403. Truncated server response:
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(4, 2).setValue(parseData.data['BTC'].quote.USD.price)
}
Hi,
I’m new in this forum.
I’ve a free account in CoinMarketCap.
If possible, can you tell me why, for every call of function i call this
start: 1,
limit: 5000
although i want the price of one crypto ?
thank’s
May I know how do I get it to show multiple 'convert'? eg USD, XAU, EUR.
I tried convert: 'USD,XAU,EUR' but no avail. I added a quote.XAU.price but got "-"
the script had no errors during execution. It used 1 credit.
also, how do i pull the 24hr change and 7d change?
tq in advance