@allratestoday/boj-exchange-rate

中文文档
1.3.27发布于 2026/11/03MITTypeScriptESM + CJS零依赖近 30 天下载 2018

Official Bank of Japan (Japan) daily exchange rates — 1 currency vs JPY, history since 1998. Zero-dependency Node.js/TypeScript client.

原始使用文档
文档目录24 节
  1. 🚀 Why this client?
  2. 🔑 Get your API key
  3. 📈 Latest published table
  4. 📦 Installation
  5. 🏁 Quick start
  6. 📚 API reference
  7. Latest pair rate
  8. Full published table
  9. Table for a date
  10. Daily time series
  11. 🗺️ Currencies covered
  12. 🏛️ Source
  13. 🧭 Reading the numbers
  14. 🧩 ERP & accounting systems
  15. 🤖 AI agents
  16. ⚖️ Published vs derived rates
  17. 🛡️ Error handling
  18. 🔷 TypeScript
  19. 📦 CommonJS
  20. 💡 Quota tips
  21. 📖 Methods reference
  22. 📥 Bulk data (no key)
  23. 🔗 Links
  24. 📜 License

Bank of Japan Exchange Rates API — boj-exchange-rate

npm version license zero dependencies TypeScript USD/JPY today rate date

Official Bank of Japan (Japan) daily 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 Bank of Japan itself prints, every business day.

🚀 Why this client?

  • 🏛️ Official published rates — Bank of Japan's own table, with the publisher's own rate_date on every response
  • 📅 History back to 1998 — 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 Bank of Japan 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.

📈 Latest published table

Latest Bank of Japan table

The image is rendered live from the keyless endpoint, 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.

The table is filled in by the daily workflow.

📦 Installation

npm install @allratestoday/boj-exchange-rate
yarn add @allratestoday/boj-exchange-rate
pnpm add @allratestoday/boj-exchange-rate

Requires Node 18+ (global fetch); also runs on Bun, Deno and edge runtimes. Scoped mirror of boj-exchange-rate — same code, same versions.

🏁 Quick start

import { getRate } from '@allratestoday/boj-exchange-rate';

const pair = await getRate('USD', 'JPY', { apiKey: 'art_live_...' });
console.log(pair.rate, pair.rate_date); // the official Bank of Japan 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('USD', 'JPY', { apiKey: 'art_live_...' });

Response:

{
  bank: 'boj',
  name: 'Bank of Japan',
  rate_date: '2026-10-09',   // Bank of Japan's own publication date
  source: 'USD',
  target: 'JPY',
  rate: 158.1,
  rate_type: 'middle',
  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 '@allratestoday/boj-exchange-rate';

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

Response:

{
  bank: 'boj',
  name: 'Bank of Japan',
  rate_date: '2026-10-09',
  rates: [
    { "base": "USD", "quote": "JPY", "type": "middle", "value": 158.1 },
    { "base": "USD", "quote": "JPY", "type": "spot", "value": 158.34 },
    // … the rest of the published table (1 currency vs JPY)
  ],
  disclaimer: '…'
}

Table for a date

Paid plans. The official table for any date since 1998 — 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 '@allratestoday/boj-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: 'USD', target: 'JPY' });

Response:

{
  bank: 'boj',
  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 '@allratestoday/boj-exchange-rate';

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

Response:

{
  bank: 'boj',
  source: 'USD',
  target: 'JPY',
  from: '2026-01-01',
  to: '2026-10-09',
  count: 152,
  rates: [
    // one entry per publication date
    { date: '2026-10-09', rate: 158.1, rate_type: 'middle', derived: false, method: 'published' },
    // …
  ],
  disclaimer: '…'
}

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


🗺️ Currencies covered

Bank of Japan currently publishes rates covering 1 currency against the JPY (as of the latest table):

🇺🇸 USD

🏛️ Source

The Bank of Japan publishes Tokyo-market USD/JPY reference rates each business day through its time-series statistics portal: the 17:00 JST spot rate and the central rate. These are the Bank's official record of the Tokyo interbank market, with history back to 1998.

🧭 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).
  • Bank of Japan quotes JPY per 1 unit of foreign currency (e.g. base: "USD", quote: "JPY" means JPY 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 (middle here); some publishers print buy/sell or several fixings for the same pair.

🧩 ERP & accounting systems

Loading the official Bank of Japan 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/boj/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('boj') 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 boj ... 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 Bank of Japan 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:

methodderivedMeaning
publishedfalseThe central bank printed this pair directly
inversetrueComputed as 1 ÷ the published opposite direction
crosstrueComputed via JPY 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('USD', 'XXX', { apiKey: 'art_live_...' });
} catch (err) {
  console.log(err.message); // human-readable reason
  console.log(err.status);  // e.g. 404
}
StatusMeaning
—Missing apiKey (thrown before any request)
400Malformed date or parameters
401Invalid API key
403Endpoint needs a paid plan (historical dates & series)
404Pair or date range not covered by Bank of Japan
429Monthly quota exceeded

🔷 TypeScript

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

import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from '@allratestoday/boj-exchange-rate';

📦 CommonJS

const { getRate } = require('@allratestoday/boj-exchange-rate');

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

💡 Quota tips

  • Rates change once per business day — 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

MethodPlanDescription
getRate(source, target, { apiKey })FreeLatest rate for one pair, resolved from the published table
getLatestRates({ apiKey })FreeThe central bank's full latest published table
getRatesForDate(date, { apiKey, source?, target? })PaidThe official table (or one pair) for a YYYY-MM-DD date
getHistory({ symbol | source+target, from?, to? }, { apiKey })PaidDaily series since 1998

📥 Bulk data (no key)

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

📜 License

MIT

版本与发布记录

@allratestoday/boj-exchange-rate 共发布 26 个版本,首次发布于 2026/08/07;过去 12 个月发布了 26 个版本。

版本发布日期距今
1.3.27latest2026/11/035 天前
1.3.262026/11/016 天前
1.3.252026/10/317 天前
1.3.242026/10/308 天前
1.3.222026/10/299 天前
1.3.192026/10/2711 天前

关于 @allratestoday/boj-exchange-rate 的常见问题

@allratestoday/boj-exchange-rate 是什么?

Official Bank of Japan (Japan) daily exchange rates — 1 currency vs JPY, history since 1998. Zero-dependency Node.js/TypeScript client.

如何安装 @allratestoday/boj-exchange-rate?

在项目目录运行 npm install @allratestoday/boj-exchange-rate,或使用 pnpm add / yarn add / bun add。

@allratestoday/boj-exchange-rate 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@allratestoday/boj-exchange-rate 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@allratestoday/boj-exchange-rate 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@allratestoday/boj-exchange-rate 可以商用吗?

@allratestoday/boj-exchange-rate 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@allratestoday/boj-exchange-rate 的下载量有多少?

根据 npm 官方下载统计,@allratestoday/boj-exchange-rate 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,018 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@allratestoday/boj-exchange-rate 还在维护吗?

最新版本 1.3.27 发布于 2026/11/03(5 天前);至今共发布 26 个版本,其中过去 12 个月发布了 26 个;首次发布于 2026/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。