Skip to content

About

Official Swiss National Bank (Switzerland) daily exchange rates — ~25 (monthly) currencies vs CHF, history since 1914. Zero-dependency Node.js/TypeScript client.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

Swiss National Bank Exchange Rates API — snb-exchange-rate

npm version license zero dependencies TypeScript EUR/CHF today rate date

Official Swiss National Bank (Switzerland) monthly exchange rates for Node.js and TypeScript. The published central bank rates behind tax filings, customs valuations, audits, and compliant invoicing — not market estimates, but the numbers Swiss National Bank itself prints, every month.

🚀 Why this client?

  • 🏛️ Official published rates — Swiss National Bank's own table, with the publisher's own rate_date on every response
  • 📅 History back to 1914 — point-in-time tables and daily series for any past date
  • 🔀 Published vs derived, always flagged — computed inverse/cross pairs carry derived: true, never mixed with official prints
  • ⚡ Zero dependencies — pure ESM + CJS over global fetch; Node 18+, Bun, Deno, and edge runtimes
  • 🔷 Type-safe — full TypeScript definitions shipped with the package
  • 🧾 Compliance-grade metadata — rate_type, publication date, and source disclaimer on every response

Official rate, not mid-market: every value here is a number Swiss National Bank itself published, fixed once printed and carrying the central bank's own rate_date — what filings and audits require. Need the live mid-market rate for pricing or display instead? Use the mid-market API or @allratestoday/sdk. The two can diverge by several percent.

🔑 Get your API key

Get a free API key at allratestoday.com/register — no credit card required. Latest rates are on every plan, including free.

⚡ Try it without a key

The latest Swiss National Bank table is also served keyless, CORS-open and edge-cached, for evaluation, embeds and AI agents:

curl "https://allratestoday.com/api/open/central-bank/snb?source=EUR&target=CHF"
const r = await fetch('https://allratestoday.com/api/open/central-bank/snb').then((x) => x.json());
console.log(r.rate_date, r.rates.length); // the central bank's latest published table, no key

The open endpoint serves the latest table only (JSON by default; add ?format=csv, xml or xlsx for a file) and asks for a visible attribution link. The client below uses the keyed API, which adds point-in-time tables and history.

📈 Latest published table

Latest Swiss National Bank table

The image is rendered live from the keyless endpoint above, so it follows the central bank's publications on npm and on GitHub alike without a new release. The same table as text is folded below for search and copy-paste: on GitHub a daily Action refreshes it whenever the central bank publishes a new table; on npm it is as of the package's publish date.

Table as text: published 2026-09-30 by Swiss National Bank — 26 rates. Updated 2026-10-20.
Base Quote Type Rate
ARS CHF monthly_average 0.00054
AUD CHF monthly_average 0.58343
BRL CHF monthly_average 0.1593254
CAD CHF monthly_average 0.58688
CNY CHF monthly_average 0.1221011
CZK CHF monthly_average 0.0388224
DKK CHF monthly_average 0.1261671
EUR CHF monthly_average 0.94312
GBP CHF monthly_average 1.0993
HKD CHF monthly_average 0.1044552
HUF CHF monthly_average 0.0025839
JPY CHF monthly_average 0.0052383
KRW CHF monthly_average 0.0006029
MXN CHF monthly_average 0.0475407
MYR CHF monthly_average 0.2013008
NOK CHF monthly_average 0.0873072
NZD CHF monthly_average 0.47256
PLN CHF monthly_average 0.2170834
RUB CHF monthly_average 0.00964
SEK CHF monthly_average 0.0839625
SGD CHF monthly_average 0.64366
THB CHF monthly_average 0.0246599
TRY CHF monthly_average 0.0168369
USD CHF monthly_average 0.81926
XDR CHF monthly_average 1.11928
ZAR CHF monthly_average 0.05052

Source: Official rates published by SNB, served by AllRatesToday. Rates are as printed by the central bank; AllRatesToday is not affiliated with it.

📦 Installation

npm install snb-exchange-rate
yarn add snb-exchange-rate
pnpm add snb-exchange-rate

Requires Node 18+ (global fetch); also runs on Bun, Deno and edge runtimes. Also published under the org scope as @allratestoday/snb-exchange-rate — same code, same versions.

🏁 Quick start

import { getRate } from 'snb-exchange-rate';

const pair = await getRate('EUR', 'CHF', { apiKey: 'art_live_...' });
console.log(pair.rate, pair.rate_date); // the official Swiss National Bank rate, on the central bank's own date

📚 API reference


Latest pair rate

Free plan and up. Pairs the central bank does not print directly are resolved from its table and flagged (see Published vs derived rates below).

const pair = await getRate('EUR', 'CHF', { apiKey: 'art_live_...' });

Response:

{
  bank: 'snb',
  name: 'Swiss National Bank',
  rate_date: '2026-09-30',   // Swiss National Bank's own publication date
  source: 'EUR',
  target: 'CHF',
  rate: 0.94312,
  rate_type: 'monthly_average',
  derived: false,
  method: 'published',
  disclaimer: 'Official rates as published by the named central bank. On weekends/holidays the most recent published rate_date is returned.'
}

Full published table

Free plan and up. The complete table for the latest publication date.

import { getLatestRates } from 'snb-exchange-rate';

const table = await getLatestRates({ apiKey: 'art_live_...' });
console.log(table.rate_date, table.rates.length);

Response:

{
  bank: 'snb',
  name: 'Swiss National Bank',
  rate_date: '2026-09-30',
  rates: [
    { "base": "EUR", "quote": "CHF", "type": "monthly_average", "value": 0.94312 },
    // … the rest of the published table (26 currencies vs CHF)
  ],
  disclaimer: '…'
}

Table for a date

Paid plans. The official table for any date since 1914 — weekends and holidays return the most recent published date, flagged via published_on_requested_date, which is exactly the in-force rate a filing needs.

import { getRatesForDate } from 'snb-exchange-rate';

const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
// Optionally narrow to one pair:
const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'EUR', target: 'CHF' });

Response:

{
  bank: 'snb',
  requested_date: '2026-06-30',
  rate_date: '2026-06-30',                // the date actually published
  published_on_requested_date: true,      // false when a weekend/holiday fell back
  rates: [ /* the full table for that date */ ],
  disclaimer: '…'
}

Daily time series

Paid plans. One resolved rate per publication date — ready for charting, revaluation runs, or audit workpapers.

import { getHistory } from 'snb-exchange-rate';

const series = await getHistory(
  { source: 'EUR', target: 'CHF', from: '2026-01-01', to: '2026-09-30' },
  { apiKey: 'art_live_...' }
);

Response:

{
  bank: 'snb',
  source: 'EUR',
  target: 'CHF',
  from: '2026-01-01',
  to: '2026-09-30',
  count: 152,
  rates: [
    // one entry per publication date
    { date: '2026-09-30', rate: 0.94312, rate_type: 'monthly_average', derived: false, method: 'published' },
    // …
  ],
  disclaimer: '…'
}

Pass { symbol: 'EUR' } instead of source/target to get the raw published rows for one currency (all rate types, no pair resolution).


🗺️ Currencies covered

Swiss National Bank currently publishes rates covering 26 currencies against the CHF (as of the latest table):

🇦🇷 ARS · 🇦🇺 AUD · 🇧🇷 BRL · 🇨🇦 CAD · 🇨🇳 CNY · 🇨🇿 CZK · 🇩🇰 DKK · 🇪🇺 EUR · 🇬🇧 GBP · 🇭🇰 HKD · 🇭🇺 HUF · 🇯🇵 JPY · 🇰🇷 KRW · 🇲🇽 MXN · 🇲🇾 MYR · 🇳🇴 NOK · 🇳🇿 NZD · 🇵🇱 PLN · 🇷🇺 RUB · 🇸🇪 SEK · 🇸🇬 SGD · 🇹🇭 THB · 🇹🇷 TRY · 🇺🇸 USD · XDR · 🇿🇦 ZAR

🏛️ Source

The Swiss National Bank publishes official franc exchange rates through its data portal. The SNB publishes monthly averages (no daily official series exists), with history reaching back to 1914 — one of the longest official exchange rate records anywhere.

🧭 Reading the numbers

  • value is always quote currency per 1 unit of base currency (base: "EUR", quote: "USD", value: 1.15 means 1 EUR = 1.15 USD).
  • Swiss National Bank quotes CHF per 1 unit of foreign currency (e.g. base: "USD", quote: "CHF" means CHF per one US dollar).
  • Need the other way round? Ask getRate(target, source) and the API inverts or crosses for you, flagged derived: true — never divide a published rate yourself in a compliance workflow.
  • rate_type tells you which of the central bank's series a row belongs to (monthly_average here); some publishers print buy/sell or several fixings for the same pair.

🧩 ERP & accounting systems

Loading the official Swiss National Bank rate into an accounting system is a supported workflow, not a hack. Step-by-step guides with the direction each system expects:

The same keyed endpoints return ?format=csv, ?format=xml and ?format=xlsx, and accept the key as ?api_key= on the URL for importers that cannot send headers:

curl "https://allratestoday.com/api/v1/central-bank/snb/latest?format=xml&api_key=art_live_..."

🤖 AI agents

  • MCP server: npx -y @allratestoday/central-bank-mcp (stdio) or the hosted endpoint https://allratestoday.com/api/mcp — tools for official rates, history, cross-bank comparison and publication calendars
  • Already using the general SDK or MCP server? Since 2026-10-01 @allratestoday/sdk 1.4+ has officialRates('snb') and @allratestoday/mcp-server 0.6+ has a get_official_rates tool — both return this source's latest table with no key, so you can add it without a second dependency
  • Claude Code plugin (no key): /plugin marketplace add AllRates-Today/claude-code-plugin then /plugin install allratestoday@allratestoday — bundles both MCP servers plus an /official-rate snb ... command
  • Evaluating? Agents can self-issue a trial key with no signup: POST https://allratestoday.com/api/agent/keys (send Content-Type: application/json) returns a 100-call key valid 7 days that covers the free-plan methods (latest table, pairs); dated tables and history need a paid plan. The MCP servers expose it as request_trial_key
  • Machine-readable site guide: llms.txt · for-ai-agents

⚖️ Published vs derived rates

If Swiss National Bank does not print a pair directly, the API resolves it from the central bank's own table and says so — official and computed values are never confused:

method derived Meaning
published false The central bank printed this pair directly
inverse true Computed as 1 ÷ the published opposite direction
cross true Computed via CHF from two published rates

🛡️ Error handling

Errors are thrown as Error with status (HTTP code) and body (the API's JSON error) attached:

try {
  const pair = await getRate('EUR', 'XXX', { apiKey: 'art_live_...' });
} catch (err) {
  console.log(err.message); // human-readable reason
  console.log(err.status);  // e.g. 404
}
Status Meaning
— Missing apiKey (thrown before any request)
400 Malformed date or parameters
401 Invalid API key
403 Endpoint needs a paid plan (historical dates & series)
404 Pair or date range not covered by Swiss National Bank
429 Monthly quota exceeded

🔷 TypeScript

Full definitions ship with the package — no @types install:

import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from 'snb-exchange-rate';

📦 CommonJS

const { getRate } = require('snb-exchange-rate');

getRate('EUR', 'CHF', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));

💡 Quota tips

  • Rates change once a month — cache the published table locally and a small monthly quota goes a long way.
  • Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.

📖 Methods reference

Method Plan Description
getRate(source, target, { apiKey }) Free Latest rate for one pair, resolved from the published table
getLatestRates({ apiKey }) Free The central bank's full latest published table
getRatesForDate(date, { apiKey, source?, target? }) Paid The official table (or one pair) for a YYYY-MM-DD date
getHistory({ symbol | source+target, from?, to? }, { apiKey }) Paid Daily series since 1914

📥 Bulk data (no key)

Need the whole archive rather than an API call? The same published tables are mirrored daily as open data:

🔗 Links

📜 License

MIT

About

Official Swiss National Bank (Switzerland) daily exchange rates — ~25 (monthly) currencies vs CHF, history since 1914. Zero-dependency Node.js/TypeScript client.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages