Singapore publishes a lot of money data: SORA every business day, T-bill auctions twice a month, COE results twice a month, CPF rates every quarter. The catch is where it lives: one agency's statistics portal, a PDF, a press release, a table on a ministry page. To chart the 6-month T-bill against CPF's 2.5%, you'd need two sources in two formats.
I run Numbers.sg, which already collects these figures for its articles. This week I opened them up as a free API: 36 datasets, JSON or CSV, no key, no sign-up:
curl https://numbers.sg/api/v1/tbill-auctions
{
"data": [{
"auction_date": "2026-11-19",
"tbill": "6-month",
"cutoff_yield_pct": 2.07,
"bid_to_cover": 1.99,
"amount_sold_sgd_m": 8600
}],
"meta": {
"as_of": "2026-11-19",
"checked_at": "2026-11-27T16:10:10+08:00",
"next_check_due": "2026-11-27T18:10:00+08:00",
"stale": false,
"rows_total": 343
}
}
(Rows and meta trimmed. The full answer has 17 fields per auction.)
This post covers what's in the API and how to use it. Most of it, though, is about the one problem I spent the most time on: an API and a web page that show the same number will drift apart unless you make that impossible.
What's in it
| Dataset | Rows | Goes back to |
|---|---|---|
| SORA and compounded SORA, daily | 5,373 | Jul 2005 |
| MAS T-bill auctions, 6-month and 1-year | 343 | May 1987 |
| Singapore Savings Bonds, every issue | 135 | Oct 2015 |
| COE bidding results, every round and category | 2,000 | Jan 2010 |
| CPF interest rates | 146 | 1955 |
| USD to SGD, daily | 8,542 | Jan 1981 |
| CPI and MAS Core inflation, monthly | 790 | Jan 1961 |
There's more: ABSD and buyer's stamp duty rates, CPF contribution rates, wage ceilings and retirement sums, income tax bands, the household electricity tariff, and 21 exchange-rate series. They come from 13 official publishers, including MAS, CPF Board, IRAS, SingStat and LTA. The full list is at /api/v1/, with an OpenAPI 3.1 file.
Every dataset has the same routes:
/api/v1/<id> latest rows (?from= &to= &fields=)
/api/v1/<id>/history every row
/api/v1/<id>.csv the same rows as CSV
/api/v1/<id>/schema JSON Schema
/api/v1/<id>/changes what changed, and when
/api/v1/<id>/as-of/YYYY-MM-DD the data as it stood that day
Using it from Python and JavaScript
In pandas, the CSV route reads like a file. Here's when a 6-month T-bill last cut off above 2% before the latest auction:
import pandas as pd
df = pd.read_csv("https://numbers.sg/api/v1/tbill-auctions.csv")
six = df[df["tbill"] == "6-month"].sort_values("auction_date")
latest = six.iloc[-1]
print(latest["auction_date"], latest["cutoff_yield_pct"])
# 2026-11-19 2.07
before = six[(six["auction_date"] < latest["auction_date"]) & (six["cutoff_yield_pct"] > 2)]
print(before.iloc[-1]["auction_date"], before.iloc[-1]["cutoff_yield_pct"])
# 2025-06-05 2.05
So the 19 November auction was the first above 2% in nearly 18 months. In JavaScript, use fields to get only the columns you need:
const res = await fetch(
"https://numbers.sg/api/v1/sora?fields=value_date,sora_pct,compounded_3m_pct"
);
const { data, meta } = await res.json();
console.log(data[0]);
// { value_date: '2026-11-26', sora_pct: 1.4628, compounded_3m_pct: 1.3891 }
if (meta.stale) console.warn("Late: the source should have updated by", meta.next_check_due);
console.log(meta.attribution.text);
// Source: Monetary Authority of Singapore, compiled by Numbers.sg (numbers.sg/rates/sora/), CC BY 4.0
CORS is open, so this works straight from a browser.
The problem: two copies of every number
Every dataset was already on the site before the API existed: an article (say, the T-bills page) with a chart, the latest figure in a sentence, and a CSV download. All three are made by one PHP function per dataset, reading a data file that a scheduled job keeps up to date.
The obvious way to build an API is a second reader: open the same data file and turn it into JSON. I didn't, because two readers will drift. Someone fixes a unit, renames a column or drops a bad row in one and forgets the other. Then the page says 2.07% and the API says 2.07 in different units, or the API keeps a row the page removed. Nobody notices until a reader does.
So the rule became: the page's CSV is the only source, and the JSON is built from it.
Step 1: the API calls the CSV's own code
The CSV downloads are served by WordPress handlers that print the file and exit. For an API request, the API sets the same query variable the CSV's URL would set, starts an output buffer, and lets that handler run. Then it picks up the printed CSV in a shutdown hook (priority 0, before WordPress flushes at 1):
// Simplified from the plugin.
// /api/v1/<id>: run the dataset's own CSV handler inside this request
set_query_var( 'ns_csv', $csv_key ); // what /data/<file>.csv would set
ob_start();
// ...the CSV handler runs at template_redirect and exits...
add_action( 'shutdown', function () {
$csv = (string) ob_get_clean();
// parse the CSV table, type each cell from the registry, send JSON
ns_api_answer( $dataset, $view, $csv );
}, 0 );
A registry file describes each dataset: which table in the CSV, field names, types, units, what an empty cell means, and the primary key. Nothing in it can change a number. It only tells the API how to read the CSV.
The JSON can't hold a figure the CSV doesn't, because there is no other place it could come from. When a handler fails, the API returns a 503 instead of guessing.
Step 2: test it anyway, every night
"By construction" holds until somebody's change breaks the construction. So at 23:50 Singapore time a job on a separate server checks every dataset in two ways:
-
JSON vs CSV, cell by cell. It reads
/api/v1/<id>/history, downloads the page's CSV itself, applies the types from the registry and compares the rows as sorted lists. It checks column count, column names, row count and every cell. -
JSON vs the article. Each dataset lists the figures its article prints from the latest row, and how they're written (
2.07,98.968,19 Nov 2026). The job fetches the article, strips the HTML and checks each one is there.
The second check caught more than I expected, because rounding has two right answers. PHP rounds halves away from zero and Python's round() rounds them to even, so the checker accepts either side of a half instead of picking one:
def shown(v, f):
"""How the article writes value v (PHP rounds halves away from zero: try both sides)."""
out = set()
for x in (v, v * (1 + 1e-12) + 1e-12, v * (1 - 1e-12) - 1e-12):
s = f'{x:,.{f["decimals"]}f}'
out |= {s, s.replace(',', '')}
return out
Last night's line from that job:
OK 36 datasets on 2026-11-26: 36 match their CSV, 36 their page;
4 new copies, 32 unchanged
A dataset that fails the CSV match isn't saved, and the job emails me. If only the article check fails, the copy is still kept, since the JSON matched the CSV, but the article needs a look.
Step 3: a dated copy, so a number can be checked later
If you quote a figure from an API, the API can change under you: a correction, a revised CPI month, a re-based index. So the same job hashes each dataset's rows and keeps a gzipped copy whenever the hash changes. On nights when nothing changed, it records "checked, unchanged".
That makes two routes possible:
-
/api/v1/sora/as-of/2026-11-26returns the data exactly as it stood at the end of that day. A day is final from midnight Singapore time. Dates before the first copy (26 Nov 2026) get a 404 that points you to/history?to=, because I'd rather say "no copy" than rebuild one I can't prove. -
/api/v1/sora/changeslists, copy by copy, the rows added, changed and removed, alongside the notes from the article's own change log.
A second copy of each file stays on the job server, so the archive doesn't depend on a single machine.
What else is in meta
Every answer carries the same meta block. The parts people use most:
-
stale: true when the last read is later than the update schedule allows. A late MAS release shows up here instead of as an old number with today's date. -
checked_atandnext_check_due: when we last read the source, and when we'll read it next. -
sources: each publisher, with a link to its terms. 28 datasets come from sources that allow reuse in writing (CC BY 4.0 for our compilation). 8 are published as figures only, because a source's website terms don't grant reuse (CPF Board's, for example), andmeta.licencesays so, with a note to check those terms before republishing a whole series. -
cite: a ready-made citation (plain, APA, BibTeX) that names the date of the data. -
finding: one dated sentence you can quote, the same one that sits under the article's chart. For T-bills today: "The 6-month T-bill cut off at 2.07% on 19 Nov 2026; it peaked at 4.4% on 8 Dec 2022."
Calculators, and an MCP server for AI agents
Some questions aren't a lookup. Stamp duty on a S$1.5m first home for a Singapore citizen:
curl "https://numbers.sg/api/v1/calc/stamp-duty?price=1500000&buyers=sc:0"
{
"total_payable_sgd": 44600,
"bsd_sgd": 44600,
"absd_rate_pct": 0,
"bsd_tiers": [
{ "amount_sgd": 180000, "rate_pct": 1, "duty_sgd": 1800 },
{ "amount_sgd": 180000, "rate_pct": 2, "duty_sgd": 3600 },
{ "amount_sgd": 640000, "rate_pct": 3, "duty_sgd": 19200 },
{ "amount_sgd": 500000, "rate_pct": 4, "duty_sgd": 20000 }
],
"pay_by": "2026-12-11",
"explanation": "ABSD 0%: a Singapore citizen buying a first home."
}
It calls the same PHP that runs the site's stamp duty calculator, and it matches all 35 of IRAS's published examples when tested over HTTP. There are also routes for CPF contributions, take-home pay, income tax and Savings Bond returns.
The same data is available as a read-only MCP server at https://numbers.sg/api/mcp (Streamable HTTP, no key), so Claude, Cursor and other MCP clients can call get_value or calculate_stamp_duty and get the figure with its source and date. It's in the official MCP registry as io.github.numbers-sg/data.
Serving it cheaply
The site runs on a small server with three PHP workers, so the API mustn't load them. Cloudflare caches each answer until the earlier of midnight in Singapore and the time that dataset's next update is due. When a job pushes new data, the dataset's API URLs are purged along with its page. There's a rate limit of 60 requests per 10 seconds per IP, and a 429 comes back as JSON.
Promises I can keep
- Ids never change. A renamed dataset redirects permanently, and the id list is append-only in git.
- Nothing breaks inside v1. New fields and datasets get added, and anything breaking waits for v2, announced six months ahead.
- Copies you can cite. The open datasets are mirrored on GitHub at numbers-sg/data, updated nightly, with a yearly archive on Zenodo (DOI 10.5281/zenodo.24576628).
The guide, with a live "make your first call" box, is at numbers.sg/developers. If a number looks wrong, or there's a Singapore dataset you'd like added, the GitHub repo has issue forms for both. I read every one.
Top comments (0)