No project description provided
Project description
twrate
A Python package for querying real-time exchange rates from major Taiwanese banks.
Overview
twrate provides a simple and efficient way to retrieve up-to-date currency exchange rates from Taiwanese banks using asynchronous fetchers and concurrent fan-out. Currently, it supports the following banks:
- Bank of Taiwan (台灣銀行)
- DBS Bank Taiwan (星展銀行)
- Sinopac Bank (永豐銀行)
- E.SUN Bank (玉山銀行)
- Line Bank (LINE Bank)
- HSBC Bank Taiwan (匯豐銀行)
- Next Bank (將來銀行)
- KGI Bank (凱基銀行)
- Cathay United Bank (國泰世華銀行)
- Mega International Commercial Bank (兆豐銀行)
- First Bank (第一銀行)
- Land Bank (土地銀行)
- Yuanta Bank (元大銀行)
- Taishin Bank (台新銀行)
- Taichung Bank (台中銀行)
- Co-operative Bank (合作金庫)
- Fubon Bank (台北富邦銀行)
Installation
pip install twrate
Requires Python 3.12+. For local development, prefer
uv(e.g.,uv syncto install anduv run twrate USDto execute the CLI inside the managed environment).
Usage
Basic Usage
import asyncio
from rich import print
from twrate import Exchange
from twrate import fetch_rates
async def main():
for exchange in Exchange:
rates = await fetch_rates(exchange)
print(rates)
if __name__ == "__main__":
asyncio.run(main())
Or fetch rates from all exchanges concurrently:
import asyncio
from twrate import Exchange
from twrate import fetch_rates
async def main():
# Fetch all rates concurrently
tasks = [fetch_rates(exchange) for exchange in Exchange]
results = await asyncio.gather(*tasks, return_exceptions=True)
all_rates = []
for exchange, result in zip(Exchange, results, strict=False):
if isinstance(result, Exception):
print(f"Error fetching {exchange.value}: {result}")
else:
all_rates.extend(result)
return all_rates
if __name__ == "__main__":
rates = asyncio.run(main())
print(rates)
Command-Line Interface
You can also use twrate directly from the command line:
# Query exchange rates for USD from all supported banks (installed via pip)
twrate USD
# Run inside the uv-managed environment when developing locally
uv run twrate USD
# Or run without installing into the current environment
uvx twrate USD
Example output:
Exchange Spot Buy Spot Sell Cash Buy Cash Sell
-------------- ---------- ----------- ---------- -----------
BANK_OF_TAIWAN 30.095 30.245 29.77 30.44
DBS 30.076 30.279 29.863 30.47
SINOPAC 30.092 30.203 29.892 30.403
ESUN 30.1 30.2 29.85 30.4
Rate Information
The Rate object provides the following information:
exchange: The bank code (e.g., "BOT" for Bank of Taiwan, "DBS" for DBS Bank)source: The source currency codetarget: The target currency code (always "TWD")spot_buy: The bank's buying rate for spot transactionsspot_sell: The bank's selling rate for spot transactionscash_buy: The bank's buying rate for cash transactionscash_sell: The bank's selling rate for cash transactionsspot_mid: A calculated property that returns the mid-rate between spot buy and sellcash_mid: A calculated property that returns the mid-rate between cash buy and sellspot_spread: Relative spread for spot transactionscash_spread: Relative spread for cash transactionssymbol: Formatted currency pair string (e.g.,USD/TWD)
License
See the LICENSE file for details.
Contributing
Contributions are welcome! The package currently supports Bank of Taiwan, DBS Bank, Sinopac Bank, E.SUN Bank, Line Bank, HSBC Bank, Next Bank, KGI Bank, Cathay United Bank, Mega International Commercial Bank, First Bank, Land Bank, Yuanta Bank, Taishin Bank, Taichung Bank, Co-operative Bank, and Fubon Bank; you can help extend the functionality to cover more Taiwanese banks.
Development
- Run tests
uv run pytest -v -s --cov=src tests
TODO
Support for additional Taiwanese banks:
- 兆豐銀行 (Mega International Commercial Bank) - https://www.megabank.com.tw/personal/savings/foreign-service/forex
- 第一銀行 (First Bank) - https://www.firstbank.com.tw/sites/fcb/touch/1565688252532
- 土地銀行 (Land Bank) - https://rate.landbank.com.tw/zh-TW/Foreign?mid=35
- 元大銀行 (Yuanta Bank) - https://www.yuantabank.com.tw/bank/exchangeRate/hostccy.do
- 台新銀行 (Taishin Bank) - https://www.taishinbank.com.tw/TSB/personal/deposit/lookup/realtime/
- 台中銀行 (Taichung Bank) - https://rate.tcbbank.com.tw/CB501014.html
- 合作金庫 (Co-operative Bank) - https://www.tcb-bank.com.tw/personal-banking/deposit-exchange/exchange-rate/spot
- 台北富邦銀行 (Fubon Bank) - https://www.fubon.com/banking/personal/deposit/exchange_rate/exchange_rate_tw.htm
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 Distributions
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.0-py3-none-any.whl.
File metadata
- Download URL: twrate-0.5.0-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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 |
1293df47247d0182ded282f5a32ecd18aa6e9d8ecac651e0999adc6b66cc6d84
|
|
| MD5 |
37745776c1165c56a963eae1096ffa35
|
|
| BLAKE2b-256 |
70130a16434e3756a5950ce199177e68fbc117e11cb600de7e7a8438e67be8ba
|