Minimalist API for stock prices in Google Sheets #2
When I initially came up with Stonkista, I was naive to think that Google Sheets would happily welcome my idea with open arms. It didn’t take long to realize I had only replaced #N/A errors with the equally useless Loading… state in cells.
My spreadsheet includes a page that tracks a portfolio in various currencies over the last few years with weekly data points. That's roughly 270 rows × 5 columns. 1350 cells. And every single one of those cells called the API via IMPORTDATA(). That couldn't work.
After a bit of research, I found that Google Sheets seems to cap external data calls at around 50 per sheet. So the only viable solution was to load data in batches.
Batching endpoints
To make that possible, I added a new type of endpoints that return prices for a given date range.
/forex/usd/pln/2021-01-01..2025-12-31
The response is a list of prices separated by a new line, which Google Sheets conveniently renders as separate rows.
3.719628473
3.742906631
3.742885424
3.742885424
3.742885424
3.762350796
3.73821299
3.745310305
3.724625761
…
That means I can now pull the full dataset with a single formula:
=IMPORTDATA("https://stonkista.com/forex/chf/pln/2021-01-01.." & TEXT(TODAY(),"yyyy-mm-dd"))
I’ve been testing this for the last few weeks, and so far it has been very reliable. Instead of hundreds of individual requests, I can load a large chunk of historical data at once and chart the portfolio over time.
The main downside is that the sheet still takes a few seconds to fetch everything when the document opens. But that seems to be a general trade-off when importing external data into Google Sheets.
For now, I’m calling this version done. It’s stable, it solves the problem I built it for, and it has held up well in my use. The only thing it’s really missing is a small website with documentation and examples so it’s easier for others to use too.