I'm using a Google script to poll CoinMarketCap's api via a Google Spreadsheet to get the latest prices, market caps, supplies etc for a number of crypto coins.
My spreadsheet looks like this...
Ticker | Coin | Price | MarketCap | Supply etc
BTC | Bitcoin | 9,000 | 130,000,000,000 | 20,000,000
ETH | Ethereum | 700 | 60,000,000,000 | 80,000,000,000
etc
Then I hit a refresh button and each cell that needs updating makes a call (simultaneously) to repetitive functions (with its ticker/coinID as a parameter identifying the row) as follows...
function getMarketCap(coinID) {
var url1 = 'https://api.coinmarketcap.com/v1/ticker/';
var full_url = url1 + coinID;
var response = UrlFetchApp.fetch(full_url);
var data = JSON.parse(response.getContentText());
return Number(data[0]['market_cap_usd']);
}
function getTotalSupply(coinID) {
//repetitive code for api call
return Number(data[0]['total_supply']);
}
//about 6 more similar functions making same call but returning different data
Apart from being inelegant, the problem is that the CoinMarketCap api has a limit of somewhere around 30 requests per minute, and although I'm querying less than 30 coins, by multiplying them by each column I'm exceeding the limit.
I know it's a super basic question, but I'm new to calling Google scripts through a spreadsheet and am struggling to see how I could in theory make a single call to the API per coin, and store the individual columns/attributes (i.e. price, marketCap, Supply etc) to be accessed by the other cells. Or perhaps it's possible to 'push' spreadsheet cell updates for the whole row from the Google script after making the first call for the row?