No project description provided
Project description
twrate ๐น๐ผ โ Taiwan Exchange Rate API and CLI for Python
twrate is a Python package and command-line tool for querying live foreign exchange rates from Taiwanese banks. It fetches TWD exchange-rate board data from multiple bank sources concurrently, so you can compare spot rates, cash rates, mid-rates, and spreads for currencies such as USD/TWD, JPY/TWD, EUR/TWD, and more.
Use twrate when you need a lightweight Taiwan exchange rate API for scripts, data pipelines, dashboards, or terminal-based rate checks.
โจ Features
- ๐ฆ Taiwan bank exchange rates from 17 supported banks.
- โก Async Python API built for concurrent fan-out with
asyncioandhttpx. - ๐ฑ CLI for quick lookup: run
twrate USDto compare USD/TWD rates across banks. - ๐ Normalized
Ratemodel with spot buy/sell, cash buy/sell, mid-rate, spread, currency pair, and fetch timestamp. - โ
Typed package with Pydantic validation and
py.typedsupport. - ๐งฉ Bank-specific fetchers that keep each source isolated and easy to maintain.
๐ฆ Supported Taiwanese banks
| Bank | Chinese name | Exchange enum |
|---|---|---|
| Bank of Taiwan | ๅฐ็ฃ้่ก | Exchange.BOT |
| DBS Bank Taiwan | ๆๅฑ้่ก | Exchange.DBS |
| SinoPac Bank | ๆฐธ่ฑ้่ก | Exchange.SINOPAC |
| E.SUN Bank | ็ๅฑฑ้่ก | Exchange.ESUN |
| LINE Bank | LINE Bank | Exchange.LINE |
| HSBC Bank Taiwan | ๅฏ่ฑ้่ก | Exchange.HSBC |
| Next Bank | ๅฐไพ้่ก | Exchange.NEXT |
| KGI Bank | ๅฑๅบ้่ก | Exchange.KGI |
| Cathay United Bank | ๅๆณฐไธ่ฏ้่ก | Exchange.CATHAY |
| Mega International Commercial Bank | ๅ ่ฑ้่ก | Exchange.MEGABANK |
| First Bank | ็ฌฌไธ้่ก | Exchange.FIRSTBANK |
| Land Bank of Taiwan | ๅๅฐ้่ก | Exchange.LANDBANK |
| Yuanta Bank | ๅ ๅคง้่ก | Exchange.YUANTA |
| Taishin Bank | ๅฐๆฐ้่ก | Exchange.TAISHIN |
| Taichung Bank | ๅฐไธญ้่ก | Exchange.TAICHUNG |
| Taiwan Cooperative Bank | ๅไฝ้ๅบซ | Exchange.COOPERATIVE |
| Fubon Bank | ๅฐๅๅฏ้ฆ้่ก | Exchange.FUBON |
Availability depends on each bank's public website or API. Some banks may publish only spot rates, only selected currencies, or temporarily unavailable data.
๐ฆ Installation
twrate requires Python 3.12 or later.
pip install twrate
For local development, use uv:
uv sync
uv run twrate USD
You can also run the CLI without installing it into the current environment:
uvx twrate USD
๐ Quick start
๐ฑ Compare USD/TWD rates in the terminal
twrate USD
Example output:
USD ๅ่กๅณๆ็ๅน
โโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโ
โ ้่ก โ ๅณๆ่ฒท้ฒ โ ๅณๆ่ณฃๅบ โ ๅณๆ้ปๅทฎ โ ็พ้่ฒท้ฒ โ ็พ้่ณฃๅบ โ ็พ้้ปๅทฎ โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ ๅฐ็ฃ้่ก (Bank ... โ 30.0950 โ 30.2450 โ 0.50% โ 29.7700 โ 30.4400 โ 2.22% โ
โ ๆๅฑ้่ก (DBS ... โ 30.0760 โ 30.2790 โ 0.67% โ 29.8630 โ 30.4700 โ 2.01% โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
๐ Fetch rates from one bank in Python
import asyncio
from twrate import Exchange, fetch_rates
async def main() -> None:
rates = await fetch_rates(Exchange.BOT)
usd_rates = [rate for rate in rates if rate.source == "USD"]
for rate in usd_rates:
print(rate.symbol, rate.spot_buy, rate.spot_sell, rate.spot_spread)
if __name__ == "__main__":
asyncio.run(main())
โก Fetch all banks concurrently
import asyncio
from twrate import Exchange, Rate, fetch_rates
async def fetch_all_rates() -> list[Rate]:
tasks = [fetch_rates(exchange) for exchange in Exchange]
results = await asyncio.gather(*tasks, return_exceptions=True)
rates: list[Rate] = []
for exchange, result in zip(Exchange, results, strict=False):
if isinstance(result, Exception):
print(f"Failed to fetch {exchange.value}: {result}")
continue
rates.extend(result)
return rates
if __name__ == "__main__":
all_rates = asyncio.run(fetch_all_rates())
usd_rates = [rate for rate in all_rates if rate.source == "USD"]
print(usd_rates)
๐ Rate model
Each fetcher returns a list of normalized Rate objects:
| Field or property | Description |
|---|---|
exchange |
Bank identifier, such as Exchange.BOT or Exchange.DBS. |
source |
Source currency code, such as USD, JPY, or EUR. |
target |
Target currency code. For this package, it is usually TWD. |
spot_buy |
Bank spot buying rate. |
spot_sell |
Bank spot selling rate. |
cash_buy |
Bank cash buying rate, if available. |
cash_sell |
Bank cash selling rate, if available. |
fetched_at |
Timestamp generated when the Rate object is created. |
spot_mid |
Mid-rate calculated from spot_buy and spot_sell. |
cash_mid |
Mid-rate calculated from cash_buy and cash_sell. |
spot_spread |
Relative spread for spot transactions. |
cash_spread |
Relative spread for cash transactions. |
symbol |
Currency pair string, for example USD/TWD. |
Missing or zero bank values are normalized to None.
๐ ๏ธ Development
Install dependencies and run commands through uv:
uv sync
uv run pytest
uv run twrate USD
Run the full test suite with coverage:
uv run pytest -v -s --cov=src tests
๐ค Contributing
Contributions are welcome. Good first issues include:
- Fixing a bank fetcher when a public page or API changes.
- Adding tests and sample fixtures for existing fetchers.
- Improving parsing for currencies with partial spot or cash data.
- Adding a new Taiwanese bank source while preserving the shared
Ratemodel.
When adding or updating a fetcher, keep it bank-specific, async-first, and covered by tests where possible.
๐ License
twrate is released under the terms in LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twrate-0.5.1.tar.gz.
File metadata
- Download URL: twrate-0.5.1.tar.gz
- Upload date:
- Size: 63.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a056e80952f7b463b3fa256a733962580c6b278e1815df7d38b6cbc0deb5fdd7
|
|
| MD5 |
4686bb9e0b4167d8806fa5af6d2a790b
|
|
| BLAKE2b-256 |
1d3a5efdb63b9c90e136f7af0d6390d9d7397187032007375fef14701356066b
|
File details
Details for the file twrate-0.5.1-py3-none-any.whl.
File metadata
- Download URL: twrate-0.5.1-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09de6409795c5cffbd0eaa00e4790a222558c5715baed9e0daf5da77e52997cc
|
|
| MD5 |
1f9a4c48f4002168b69c44cd621fb84d
|
|
| BLAKE2b-256 |
ee2475506b15ca0a5a696c53f7dde8675629f2dc7962b4776b0ddf1895d02c9c
|