/** * IQWealth for Google Sheets · https://iraqsm.com/sheets * * Install once: Extensions → Apps Script → paste this file → Save. * Then, in any cell of this spreadsheet: * * =IQWEALTH("USD") dollar in Baghdad (sell), IQD * =IQWEALTH("USD-BUY") … buy · "USD-100" per 100 dollars · "USD-OFFICIAL" Central Bank rate * =IQWEALTH("GOLD21") gold 21k per mithqal, IQD (GOLD24, GOLD22, GOLD18; add -GRAM for a gram) * =IQWEALTH("ISX60") Iraq Stock Exchange index * =IQWEALTH("EUR") IQD per euro at the Baghdad dollar (GBP, TRY, SAR, AED, KWD, JOD, IRR …) * =IQWEALTH("BBOB") last close of an ISX share * =IQWEALTH("BBOB", "change") % change · "prev" · "value" · "volume" · "trades" · "date" * * Figures are IQWealth's (iraqsm.com): session-end or daily readings, never * real-time. Values are cached for 10 minutes. Free with attribution. */ /** * Iraqi market figures from IQWealth (iraqsm.com). * * @param {string} item USD, USD-BUY, USD-100, USD-OFFICIAL, GOLD21, ISX60, EUR, or an ISX ticker like BBOB. * @param {string} field Optional, for tickers: close (default), change, prev, value, volume, trades, date. * @return The figure (IQD unless stated). * @customfunction */ function IQWEALTH(item, field) { if (!item) throw new Error('Give a name, e.g. =IQWEALTH("USD")'); var name = String(item).trim().toLowerCase(); var f = field ? String(field).trim().toLowerCase() : ''; var key = 'iqw:' + name + ':' + f; var cache = CacheService.getScriptCache(); var text = cache.get(key); if (text === null) { var url = 'https://iraqsm.com/api/sheet/' + encodeURIComponent(name) + (f ? '?field=' + encodeURIComponent(f) : ''); var res = UrlFetchApp.fetch(url, { muteHttpExceptions: true }); if (res.getResponseCode() !== 200) throw new Error('Unknown name "' + item + '". See iraqsm.com/sheets'); text = res.getContentText().trim(); cache.put(key, text, 600); } var n = Number(text); return isNaN(n) ? text : n; }