LearnTutorial

Gold, exchange rates and crypto in one Google Sheet

Pull exchange rates, gold, silver and crypto into one portfolio tab, valued in your own currency and refreshed every hour.

One Apps Script file can value a mixed portfolio in Google Sheets. It reads currencies from the Exchangerate API, gold and silver from the Goldprice API and crypto from the coinprice API, writes each value in your home currency and runs again every hour.

  • One Code.gs file prices cash, gold, silver and crypto in the currency you type in cell B1.
  • IMPORTDATA cannot send a key header, so the requests run in Apps Script with UrlFetchApp.
  • An hourly refresh of the example fits inside all three free plans.
  • New prices are written only when every row has one, so a failed refresh keeps the last good numbers.

What the sheet shows

A tab called Portfolio has one row for each thing you own. Cash rows take a currency code and an amount. Metal rows take XAU for gold or XAG for silver, measured in grams, and crypto rows take a coin id such as bitcoin. Cell B2 adds up the values. Our run on 25 Nov 2026 at 06:30 UTC, with euros as the home currency, gave this:

HoldingPrice in EURValue in EUR
1,500 USD0.914451,371.67
800 GBP1.195969956.78
2,000 EUR1.002,000.00
20 g gold103.653522 per gram2,073.07
500 g silver1.188123 per gram594.06
0.05 bitcoin53,917.0913612,695.85
1.2 ethereum1,512.0646861,814.48
Total11,505.91

Get three API keys

No free plan asks for a card. On the free plans, exchange rates and metal prices arrive 15 minutes late. If you show the numbers in something commercial, each free plan asks for a visible link to the site they came from.

Why IMPORTDATA is not enough

IMPORTDATA fetches a web address and cannot send a header. These requests carry your key in the Authorization header, so the sheet uses Apps Script, which can send headers with UrlFetchApp. Without a key coinprice answers 401, as its Google Sheets crypto guide explains.

Try the requests first

Set your three keys as shell variables and run each command. The responses shown are real, laid out one field per line.

Exchange rates. One request covers every cash row. With USD as the base, one unit of a currency is worth rates[home] / rates[code] in your home currency. See the latest rates reference.

Exchange rates · request
curl "https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,USD,GBP" \  -H "Authorization: Bearer $EXCHANGERATE_API_KEY"
Exchange rates · response
{  "result": "success",  "base": "USD",  "source": "live",  "sources": {    "EUR": "live",    "USD": "live",    "GBP": "live"  },  "market_session": "open",  "timestamp": "2026-11-25T06:30:35Z",  "data_updated_at": "2026-11-25T06:14:59Z",  "effective_at": {    "EUR": "2026-11-25T06:14:59Z",    "GBP": "2026-11-25T06:14:59Z",    "USD": "2026-11-25T06:14:59Z"  },  "rates": {    "EUR": 0.91445,    "USD": 1,    "GBP": 0.76461  },  "stale": {    "EUR": false,    "USD": false,    "GBP": false  },  "derived_symbols": [],  "unavailable": [],  "notice": "Indicative rates, not for settlement."}

Gold and silver. The convert endpoint prices one gram of a metal in your currency, so each metal is one request. The rate field keeps the full precision and result is rounded. See the convert reference.

Gold · request
curl "https://api.goldprice.dev/v1/convert?from=XAU&to=EUR&amount=1&unit=gram" \  -H "Authorization: Bearer $GOLDPRICE_API_KEY"
Gold · response
{  "from": "XAU",  "to": "EUR",  "amount": "1.0",  "rate": "103.6535221039983542933052424",  "result": "103.65",  "unit": "gram",  "timestamp": "2026-11-25T06:15:02.593204Z"}
Silver · request
curl "https://api.goldprice.dev/v1/convert?from=XAG&to=EUR&amount=1&unit=gram" \  -H "Authorization: Bearer $GOLDPRICE_API_KEY"
Silver · response
{  "from": "XAG",  "to": "EUR",  "amount": "1.0",  "rate": "1.188122911069543196534221538",  "result": "1.19",  "unit": "gram",  "timestamp": "2026-11-25T06:15:02.593204Z"}

Crypto. One request covers every coin and answers in your currency. See the coinprice API docs.

Crypto · request
curl "https://api.coinprice.dev/v2/simple/price?ids=bitcoin,ethereum&vs_currencies=eur&include_last_updated_at=true" \  -H "Authorization: Bearer $COINPRICE_API_KEY"
Crypto · response
{  "bitcoin": {    "eur": 53917.091361293395,    "last_updated_at": 1795588234  },  "ethereum": {    "eur": 1512.06468595884,    "last_updated_at": 1795588234  }}

Add the Apps Script

  1. In a new Google Sheet, open Extensions, then Apps Script.
  2. Replace the contents of Code.gs with the code below and save.
  3. Open Project Settings, find Script properties and add EXCHANGERATE_API_KEY, GOLDPRICE_API_KEY and COINPRICE_API_KEY, each with its key as the value.

The keys never appear in a cell. Anyone who can edit the spreadsheet can still open the script and read them, so keep this sheet to yourself or share it as view only. For a sheet that several people edit, call the APIs from your own server.

Code.gs
const SHEET = 'Portfolio'const FIRST_ROW = 5function onOpen() {  SpreadsheetApp.getUi()    .createMenu('Portfolio')    .addItem('Set up the sheet', 'setUpPortfolio')    .addItem('Refresh now', 'refreshPortfolio')    .addItem('Refresh every hour', 'refreshEveryHour')    .addToUi()}// Creates the tab with example holdings. It leaves an existing tab alone.function setUpPortfolio() {  const book = SpreadsheetApp.getActive()  if (book.getSheetByName(SHEET)) return  const sheet = book.insertSheet(SHEET)  sheet.getRange('A1:B3').setValues([['Home currency', 'EUR'], ['Total', '=SUM(E5:E)'], ['Last refresh', '']])  sheet.getRange('A4:F4').setValues([['Type', 'Asset', 'Quantity', 'Price', 'Value', 'Price time']])  sheet.getRange('A5:C11').setValues([    ['cash', 'USD', 1500],    ['cash', 'GBP', 800],    ['cash', 'EUR', 2000],    ['metal', 'XAU', 20], // grams of gold    ['metal', 'XAG', 500], // grams of silver    ['crypto', 'bitcoin', 0.05],    ['crypto', 'ethereum', 1.2],  ])  sheet.getRange('B2').setNumberFormat('#,##0.00')  sheet.getRange('D5:D').setNumberFormat('#,##0.00####') // up to six decimals for small prices  sheet.getRange('E5:E').setNumberFormat('#,##0.00')  sheet.getRange('B3').setNumberFormat('yyyy-mm-dd hh:mm')  sheet.getRange('F5:F').setNumberFormat('yyyy-mm-dd hh:mm')  sheet.setColumnWidths(1, 6, 140)}// One GET with the key in the Authorization header. Any status but 200 stops the refresh.function getJson(url, keyName) {  const key = PropertiesService.getScriptProperties().getProperty(keyName)  if (!key) throw new Error('Add ' + keyName + ' under Project Settings, Script properties')  const res = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + key }, muteHttpExceptions: true })  if (res.getResponseCode() !== 200) {    throw new Error(url.split('/')[2] + ' answered ' + res.getResponseCode() + ': ' + res.getContentText().slice(0, 200))  }  return JSON.parse(res.getContentText())}// A holding's lookup name: currency and metal codes in capitals, coin ids in lower case.function assetName(type, asset) {  const text = String(asset).trim()  return type === 'crypto' ? text.toLowerCase() : text.toUpperCase()}function refreshPortfolio() {  const sheet = SpreadsheetApp.getActive().getSheetByName(SHEET)  const home = String(sheet.getRange('B1').getValue()).trim().toUpperCase()  const count = sheet.getLastRow() - FIRST_ROW + 1  if (count < 1) return  const rows = sheet.getRange(FIRST_ROW, 1, count, 2).getValues().map(([type, asset]) => {    const kind = String(type).trim().toLowerCase()    return { type: kind, asset: assetName(kind, asset) }  })  const assets = (type) => [...new Set(rows.filter((row) => row.type === type).map((row) => row.asset))]  const prices = {} // "type asset" -> [price of one unit in the home currency, time of that price]  // Exchange rates: one request for every cash row  const cash = assets('cash')  if (cash.length) {    const symbols = [...new Set([home, ...cash])].join(',')    const fx = getJson('https://api.exchangerate.dev/v1/latest/USD?symbols=' + symbols, 'EXCHANGERATE_API_KEY')    cash.forEach((code) => {      prices['cash ' + code] = [fx.rates[home] / fx.rates[code], new Date(fx.data_updated_at)]    })  }  // Gold and silver: one request per metal, priced per gram  assets('metal').forEach((metal) => {    const url = 'https://api.goldprice.dev/v1/convert?from=' + metal + '&to=' + home + '&amount=1&unit=gram'    const quote = getJson(url, 'GOLDPRICE_API_KEY')    prices['metal ' + metal] = [Number(quote.rate), new Date(quote.timestamp)]  })  // Crypto: one request for every coin  const coins = assets('crypto')  if (coins.length) {    const vs = home.toLowerCase()    const url = 'https://api.coinprice.dev/v2/simple/price?ids=' + coins.join(',') +      '&vs_currencies=' + vs + '&include_last_updated_at=true'    const data = getJson(url, 'COINPRICE_API_KEY')    coins.filter((id) => data[id]).forEach((id) => {      prices['crypto ' + id] = [data[id][vs], new Date(data[id].last_updated_at * 1000)]    })  }  // Write only when every row has a price, so a failed refresh keeps the last good numbers  const output = rows.map((row, i) => {    if (!row.type && !row.asset) return ['', '', '']    const line = FIRST_ROW + i    const price = prices[row.type + ' ' + row.asset]    if (!price || !(price[0] > 0)) throw new Error('No price for row ' + line + ': ' + row.type + ' ' + row.asset)    return [price[0], '=C' + line + '*D' + line, price[1]]  })  sheet.getRange(FIRST_ROW, 4, count, 3).setValues(output)  sheet.getRange('B3').setValue(new Date())}// Safe to run twice: it replaces its own timer.function refreshEveryHour() {  ScriptApp.getProjectTriggers()    .filter((trigger) => trigger.getHandlerFunction() === 'refreshPortfolio')    .forEach((trigger) => ScriptApp.deleteTrigger(trigger))  ScriptApp.newTrigger('refreshPortfolio').timeBased().everyHours(1).create()}

Run it and set the timer

  1. Reload the spreadsheet. A Portfolio menu appears in the menu bar.
  2. Choose Portfolio, then Set up the sheet. Google asks you to authorise the script the first time; choose the item again if nothing happens.
  3. Type your home currency in B1 and replace the example holdings in columns A to C.
  4. Choose Refresh now, then Refresh every hour.

The timer runs while the spreadsheet is closed, and choosing Refresh every hour again still leaves one timer. The Last refresh cell tells you when the numbers were last written. Column F has the time of each price, which matters at the weekend: currency rates hold their Friday close while crypto keeps trading.

Currencies and request limits

Cell B1 takes the 35 currencies the Goldprice API converts into: AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EGP, EUR, GBP, HKD, HUF, IDR, ILS, INR, ISK, JPY, KRW, MXN, MYR, NOK, NPR, NZD, PHP, PKR, PLN, RON, SEK, SGD, THB, TRY, USD, VND and ZAR. Cash rows are not limited to that list.

One refresh of the example makes four requests: one for exchange rates, two for metals and one for crypto. An hourly timer therefore uses at most 744 Exchangerate, 1,488 Goldprice and 744 coinprice requests in a 31-day month. Refreshing by hand more than five times in a minute goes over the Goldprice free limit.

MessageCauseFix
Add GOLDPRICE_API_KEY under Project Settings, Script propertiesA script property is missing or misspelled.Add it under the name in the message.
answered 401That API did not accept the key.Copy the key again into its script property.
answered 400 with unsupported_currencyGoldprice does not convert into the currency in B1.Pick one of the 35 currencies above.
answered 400 with unsupported symbolA currency code is wrong.Check the three-letter codes in B1 and the cash rows.
answered 429A plan limit was reached.Wait a minute. If the month’s requests are used up, wait for the reset or change plan.
No price for row 11The coin id or the Type cell in that row is wrong.Use cash, metal or crypto, and a coin id such as bitcoin.

If you only need one kind of price, the single guides are shorter: exchange rates in Google Sheets, the gold portfolio tracker in Google Sheets and Google Sheets crypto prices.

Questions

Can IMPORTDATA call these APIs with my key?

No. IMPORTDATA fetches a web address and cannot send a header, and the key travels in the Authorization header. Apps Script sends it with UrlFetchApp.

Does an hourly refresh fit the free plans?

Yes, for the example. In a 31-day month it uses at most 744 of the 5,000 Exchangerate requests, 1,488 of the 5,000 Goldprice requests and 744 of the 50,000 coinprice calls.

How do I add another currency or coin?

Add a row with the type, the currency code or coin id and the amount, then choose Refresh now. All cash rows share one request and so do all crypto rows. Each metal takes one Goldprice request.

Why is the gold or currency price a few minutes old?

The free plans of the Exchangerate and Goldprice APIs deliver prices 15 minutes late. Column F shows the time of every price.

Keep reading

Start with a free API key

5,000 requests a month on the free plan. No credit card.

Get a free key