// ONLYOFFICE Custom Function // Location: View -> Macros -> Custom Functions // Used on: "HSA Investiments Choices" tab (mutual funds -- Finnhub has no NAV coverage) // Data source: self-hosted STOCKPROXY service (see server_stockproxy.md / stockproxy_app.py) // https://stocks.kingdezigns.com // // Real shared secret lives in Vaultwarden -- never commit the real secret to this file. // // Usage in a cell: // =FUNDPRICE("MKDVX") // =FUNDPRICE_HIST("MKDVX", TEXT($B$3,"yyyy-mm-dd")) <- date MUST be passed as text (function () { var PROXY_BASE = "https://stocks.kingdezigns.com"; var PROXY_SECRET = "YOUR_PROXY_SECRET_HERE"; /** * Current mutual fund price via your own proxy. * @customfunction * @param {string} ticker Ticker symbol, e.g. "MKDVX" * @returns {any} Latest price, or an error string */ async function FUNDPRICE(ticker) { var url = PROXY_BASE + "/current?ticker=" + encodeURIComponent(ticker) + "&key=" + PROXY_SECRET; try { var r = await fetch(url); var data = await r.json(); if (data && typeof data.price === "number") { return data.price; } return "#N/A"; } catch (e) { return "#ERROR"; } } /** * Historical fund price on/before a given date via your own proxy. * @customfunction * @param {string} ticker Ticker symbol, e.g. "MKDVX" * @param {string} dateStr Date as YYYY-MM-DD (wrap the date cell with TEXT(cell,"yyyy-mm-dd")) * @returns {any} Historical closing price, or an error string */ async function FUNDPRICE_HIST(ticker, dateStr) { var url = PROXY_BASE + "/historical?ticker=" + encodeURIComponent(ticker) + "&date=" + encodeURIComponent(dateStr) + "&key=" + PROXY_SECRET; try { var r = await fetch(url); var data = await r.json(); if (data && typeof data.price === "number") { return data.price; } return "#N/A"; } catch (e) { return "#ERROR"; } } Api.AddCustomFunction(FUNDPRICE); Api.AddCustomFunction(FUNDPRICE_HIST); })();